Elasticsearch, get average document length

后端 未结 4 1207
陌清茗
陌清茗 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:26

    The _size mapping field, if enabled, should give you the size of each document for free. Combining this with the avg aggregation should get you what you want. Something like:

    {
      "query" : {"match_all" : {}},
      "aggs" : {"avg_size" : {"avg" : {"terms" : {"field" : "_size"}}}}
    }
    

提交回复
热议问题