Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch aggs returns 10 buckets only

I am running an aggs query and specifying the size of 100, but ES only returns 10 buckets back. Why? What am I missing?

{   
  "size": 100
   ,"query": {
      "bool": {
        "must": [
          { "term": {"app": "cnn"} }
        ]
      }
    }
   ,"aggs": {
    "unique_client": {
      "terms": {"field": "client"}    
      }     
    }
}
like image 212
epipko Avatar asked Nov 11 '15 17:11

epipko


2 Answers

Set the top size parameter to zero to signify that it is an aggregation. The number of buckets returned is set by specifying the size INSIDE the terms aggregation braces.

{   
  "size": 0
   ,"query": {
      "bool": {
        "must": [
          { "term": {"app": "cnn"} }
        ]
      }
    }
   ,"aggs": {
    "unique_client": {
      "terms": {
        "field": "client",
        "size" : 100
      }
     }     
    }
}

If you set it to 0 the value will default to Integer.MAX_VALUE

like image 155
Vanlightly Avatar answered Oct 21 '22 09:10

Vanlightly


outer size is for total number of documents you get back for your query, so size = 100 returns 100 documents, for getting 100 aggregations bucket, specify size inside your unique_client aggs like this

{   
  "size": 0
   ,"query": {
      "bool": {
        "must": [
          { "term": {"app": "cnn"} }
        ]
      }
    }
   ,"aggs": {
    "unique_client": {
      "terms": {"field": "client"},
      "size" : 100
      }     
    }
}

By Default size of aggregations is 10, that is why you get 10 results, I have made outer size = 0 to get only aggregations.

like image 44
ChintanShah25 Avatar answered Oct 21 '22 09:10

ChintanShah25