Using a prefix query/filter
The prefix query/filter is used when only the starting part of a term is known. It allows you to complete truncated or partial terms.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script chapter_05/populate_query.sh
, available in the code bundle for this book.
How to do it...
In order to execute a prefix query/filter, perform the following steps:
Execute a prefix query from the command line:
curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "prefix": { "uuid": "333" } } }'
The result returned by ElasticSearch is the same as in the previous recipe.
If you want to use the prefix query in a filter, this is how the query should look:
curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "filtered": { "filter": { "prefix": { "uuid": "333" } }, "query": { "match_all": {} ...