Using an ID query/filter
The ID query/filter allows you to match documents by their IDs.
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 ID queries/filters, perform the following steps:
The ID query to fetch IDs
1
,2
,3
of the typetest-type
is in this form:curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "ids" : { "type" : "test-type", "values" : ["1", "2", "3"] } } }'
The same query can be converted to a filter query, similar to this one:
curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "filtered": { "filter": { "ids" : { "type" : "test-type", "values" : ["1", "2", "3"] } }, "query": { "match_all": {} } } } }'
How it works...
Querying/filtering by...