Executing the filter aggregation

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.

Getting ready

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.

How to do it...

We need to compute two different filter aggregations that are:

  • The count of documents that have ullam as tag
  • The count of documents that have age equal to 37

To execute filter aggregations, we will perform the steps given as follows:

  1. 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' ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.