Elasticsearch, get average document length

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

    Shot in the dark, but facets or aggregations combined with a script might do it.

    {
        ...,
    
        "aggs" : {
            "avg_length" : { "avg" : { "script" : "doc['_all'].length" } }
        }
    }
    

提交回复
热议问题