Book Image

ElasticSearch Blueprints

Book Image

ElasticSearch Blueprints

Overview of this book

Table of Contents (15 chapters)
Elasticsearch Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Terms aggregation giving weird results


Let's consider an aggregation in the Author field to get the statistics of each author name:

curl -XPOST  "http://localhost:9200/news/public/_search?pretty&search_type=count" -d '{
    "aggs" : {
      "authors" : {
        "terms" : {
          "field" : "Author"
        }
      }
    }
}'

By giving search_type=count, we make sure that we receive only the aggregation results and not hits or rather, the top-10 results.

The response we get for this is as follows:

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "authors" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [ {
        "key" : "shankar",
        "doc_count" : 3
      }, {
        "key" : "anjali",
        "doc_count" : 2
      }, {
        "key" : "ram",
        "doc_count" : 1...