弹性搜索,获取平均文档长度 [英] Elasticsearch, get average document length

查看:107
本文介绍了弹性搜索,获取平均文档长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在弹性搜索中是否有更好的方法(除了发布匹配所有查询和手动平均所有返回的文档的长度)以获取特定索引的平均文档长度?

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 length for a specific index?

推荐答案

_大小映射字段,如果启用,应该免费给你每个文档的大小。将它与 avg 聚合结合应该可以让你满意。如下:

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"}}}}
}

这篇关于弹性搜索,获取平均文档长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆