Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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' -d '
    {
      "query": {
        "match_all": {}
      },
      "aggregations": {
        "ullam_docs": {
          "filter" : {
            "term" : { "tag" : "ullam" }
          }
        },
        "age37_docs": {
          "filter" : {
            "term" : { "age"...