Executing filter/query facets
Sometimes, we don't need complex computation, but only the number of hits that verifies a particular query or filter. To obtain this result, the filter/query facet is used.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script available in the online code.
How to do it...
For executing filter/query facets, we will perform the steps given as follows:
We need to compute two different filter facets, which are:
The count of documents that have
"ullam"
as tagThe count of documents that have age equal to
37
The query to execute these facets is:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?from=0&pretty=true&size=0' -d ' { "query": { "match_all": {} }, "facets": { "ullam_docs": { "filter" : { "term" : { "tag" : "ullam" } } }, "age37_docs": { "filter" : { "term" : { "age" : 37 } } } } }'
In this case we...