Querying/filtering for multiple terms
The previous type of search works very well if you need to search for a single term. If you want to search for multiple terms, you can do that in two ways: using an AND
/OR
filter or using the multiple term query.
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 terms
query/filter, perform the following steps:
Execute a terms query from the command line:
curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "terms": { "uuid": ["33333", "32222"] } } }'
The result returned by ElasticSearch is the same as in the previous recipe.
If you want to use the terms 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": { ...