Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return only aggregation stats in an ElasticSearch query?

Is it possible to exclude documents from an aggregation query? I just need to know "count" and "sum" and do not need hits. I did it like this:

{
  "query": {
    "match_all": {

    }
  },
  "aggs": {
    "my_agg": {
      "stats": {
        "field": "country_id"
      }
    }
  }
}
like image 548
ehsan shirzadi Avatar asked Sep 30 '14 06:09

ehsan shirzadi


People also ask

What is aggregation query Elasticsearch?

Elasticsearch organizes aggregations into three categories: Metric aggregations that calculate metrics, such as a sum or average, from field values. Bucket aggregations that group documents into buckets, also called bins, based on field values, ranges, or other criteria.

What is terms aggregation in Kibana?

What is Kibana Aggregation? Aggregation refers to the collection of documents or a set of documents obtained from a particular search query or filter. Aggregation forms the main concept to build the desired visualization in Kibana.

What is elastic search?

Elasticsearch is a distributed search and analytics engine built on Apache Lucene. Since its release in 2010, Elasticsearch has quickly become the most popular search engine and is commonly used for log analytics, full-text search, security intelligence, business analytics, and operational intelligence use cases.

What is Sum_other_doc_count?

sum_other_doc_count is the number of documents that didn't make it into the the top size terms.


1 Answers

To focus only on aggregation with a match_all query, you could simply use "size":0 (this specifies you want no query results) with no query:

curl -XPOST "http://localhost:9200/indexname/doctype/_search" -d'
{
    "size": 0, 
    "aggs": {
        "my_agg": {
            "stats": {
                "field": "country_id"
            }
        }
    }
}'
like image 54
Kevin. Avatar answered Sep 29 '22 01:09

Kevin.