Sometimes, we need to reduce the number of hits in our aggregation to satisfy a particular filter. To obtain this result, the filter aggregation is used.
You need a working ElasticSearch cluster and an index populated with the script (chapter_06/test_filter_aggregation.sh)
available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
We need to compute two different filter aggregations that are:
The count of documents that have
ullam
as tagThe count of documents that have age equal to 37
To execute filter aggregations, we will perform the steps given as follows:
The query to execute these aggregations is as follows:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?size=0&pretty=true' -d ' { "query": { "match_all": {} }, "aggregations": { "ullam_docs": { "filter" : { "term" : { "tag" : "ullam" } } }, "age37_docs": { "filter" : { "term" : { "age"...