Elastic search get bucket count


#1

I have the following query:

GET images/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"appID.raw": "myApp"
}
}
]
}
},
"size": 0,
"aggs": {
"perDeviceAggregation": {
"terms": {
"field": "deviceID",
"min_doc_count": 50000
}
}
}

This query returns a "buckets" array, but I would like to change it so it returns only the length of the array, without the array itself.

Thanks.


(Joshua Rich) #2

This sounds like something that could be done within your client? I'm not sure Elasticsearch provides an easy way to count the number of buckets.


(Wanglifengwf) #3

you can do like this:

POST index/_search
{
  "size": 0,
  "aggs": {
    "perDeviceAggregation": {
      "terms": {
        "field": "deviceID"
      }
    },
    "count":{
      "cardinality": {
        "field": "deviceID"
      }
    }
  }
}

#4

If I understand this correctly, your query will return the number of images per device, whereas what I want is to get the total number of devices that have a number of images above the threshold.


(Wanglifengwf) #5

Are you have a test on my query?

The query is return the total count deviceId and some deviceId details


(Wanglifengwf) #6

the result like this:

"aggregations": {
    "aads": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "aa",
          "doc_count": 1
        },
       {
          "key": "bb",
          "doc_count": 1
        }
      ]
    },
    "count": {
      "value": 2
    }
  }

(system) #7