Elasticsearch, get average document length

后端 未结 4 1218
陌清茗
陌清茗 2021-01-02 04:47

Is there any better way in elasticsearch (other than issuing a match all query and manually averaging over the length of all returned documents) to get the average document

4条回答
  •  误落风尘
    2021-01-02 05:02

    In ElasticSearch 6.2 you should just use the following line (no need to add 'terms'):

      "aggs" : 
          {"avg_size" : 
               {"avg" : 
                   {"field" : "_size"}}}
    

    See details here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html

提交回复
热议问题