Elastic search that gets average doc_count from term aggregation

I have a query for terms as follows in a search for elasticity.

GET http://localhost:9200/adapters/request/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match" : { "adapterName" : "EnginePushableAdapter" }
            },
            "filter": {
                "range" : {
                    "request.requestTime" : {
                        "gte" : 1492080226172,
                        "lte" : 1492080725964
                    }
                }
            }
        }
    }, 
    "aggs" : {
        "call_count" : {
            "terms" : {
                "field" : "deviceId"          
            }
        }
    }
}

      

Is there a way to calculate the average doc_count returned by term aggregation? like this

    "avg_agg" : {
        "avg": { "field": "call_count.doc_count" }

    }

      

In other words, I want to average the previous aggregation fields.

+3


source to share


1 answer


I think you can search for average bucket aggregation.

https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-pipeline-avg-bucket-aggregation.html



Try something like

...
"my_count_avg": {
  "avg_bucket": {
    "buckets_path": "call_count>_count"
  }
}

      

+2


source







All Articles