elasticsearch - How to get max or avg from Bucket Aggregation -


how can avg or max doc_count buckets.

there many examples of how numeric fields, need nax count of distinct devices.

my query:

post sessions/_search {   "size": 0,   "query": {     ...   },   "aggs": {     "1": {       "terms": {         "size" : 10,         "order" : {             "_count" : "desc"         },         "field": "deviceid"       }     }   } } 

example result:

  "aggregations": {       "1": {          "doc_count_error_upper_bound": 62,          "sum_other_doc_count": 326057,          "buckets": [             {                "key": "878f6sdb0245e3d8bd",                "doc_count": 230             },             {                "key": "ee43b17fsfc00fd04f",                "doc_count": 224             },             {                "key": "bdcdeb0eeaffcfe748",                "doc_count": 141             }, ... 

terms aggregation default sorts bucket in decreasing order of doc_count. if fetch first bucket, 1 maximum doc_count.

query:

post sessions/_search {  "size": 0,  "query": {  ... }, "aggs": { "1": {   "terms": {     "size" : 1,     "order" : {         "_count" : "desc"     },     "field": "deviceid"    }   }  } } 

i don't think finding average possible using 1 query.but can use below queries result

sum of doc counts = total documents in index.

first find total documents using

get /order/order/_count 

then find buckets count using cardinality

{ "aggs" : {     "device_count" : {         "cardinality" : {             "field" : "deviceid"         }     }    }  } 

then divide both results average.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -