内容简介:项目中使用Elastic Search做搜索,在聚合产品的标签的时候,我发现标签的种类有很多超过了10个(这一点很重要),但是聚合标签出来的数据只有10个,缺少了很多标签,查询的语句如下:百思不得其解,看文档发现自己的查询和Terms的聚合使用都是没有任何问题的,但是出来的数据为什么会少呢?于是昨天上午花了将近一个小时的时间才找到问题的所在,下面是文档上对返回数据的一个解释:By default, the terms aggregation will return the buckets for the
项目中使用Elastic Search做搜索,在聚合产品的标签的时候,我发现标签的种类有很多超过了10个(这一点很重要),但是聚合标签出来的数据只有10个,缺少了很多标签,查询的语句如下:
{
"from" : 0,
"size" : 15,
"query" : {
"bool" : {
"must" : [ {
"terms" : {
"categoryId" : [ 1046, 1045, 1044 ]
}
}, {
"terms" : {
"tagList.id" : [ 1063, 1138, 1115, 1142 ]
}
} ]
}
},
"aggregations" : {
"categoryId" : {
"terms" : {
"field" : "categoryId"
}
},
"tagList.tagContent" : {
"terms" : {
"field" : "tagList.tagContent"
}
}
}
}
百思不得其解,看文档发现自己的查询和Terms的聚合使用都是没有任何问题的,但是出来的数据为什么会少呢?于是昨天上午花了将近一个小时的时间才找到问题的所在,下面是文档上对返回数据的一个解释:
By default, the terms aggregation will return the buckets for the top ten terms ordered by the doc_count. One can change this default behaviour by setting the size parameter.
Size
The size parameter can be set to define how many term buckets should be returned out of the overall terms list. By default, the node coordinating the search process will request each shard to provide its own top size term buckets and once all shards respond, it will reduce the results to the final list that will then be returned to the client. This means that if the number of unique terms is greater than size, the returned list is slightly off and not accurate (it could be that the term counts are slightly off and it could even be that a term that should have been in the top size buckets was not returned).
原来Elastic Search对数据聚合默认返回10个,我聚合的数据术语桶超过了10个,可以自行设置size来返回不同数量的术语桶。于是乎,查询的语句修改成下面的样子就成功返回了所有的数据:
{
"from" : 0,
"size" : 15,
"query" : {
"bool" : {
"must" : [ {
"terms" : {
"categoryId" : [ 1046, 1045, 1044 ]
}
}, {
"terms" : {
"tagList.id" : [ 1063, 1138, 1115, 1142 ]
}
} ]
}
},
"aggregations" : {
"categoryId" : {
"terms" : {
"field" : "categoryId",
"size" : 100
}
},
"tagList.tagContent" : {
"terms" : {
"field" : "tagList.tagContent",
"size" : 100
}
}
}
}
其实我还有一个问题,在使用 Range范围聚合 的时候,发现聚合的数据不准确,就是说10-20本来就30条记录,但是聚合显示这个范围的数据只有10个,这个问题我暂时还没有找到原因,有人知道的话,我很高兴有人能告诉我!
最后更新于 2018-08-30 10:50:34 并被添加「elasticsearch」标签,已有 1 位童鞋阅读过。
以上所述就是小编给大家介绍的《Elastic Search搜索数据Terms聚合返回的不正确的问题》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
机器学习基础教程
(英)Simon Rogers,、Mark Girolami / 郭茂祖、王春宇 刘扬 刘晓燕、刘扬、刘晓燕 / 机械工业出版社 / 2014-1 / 45.00
本书是一本机器学习入门教程,包含了数学和统计学的核心技术,用于帮助理解一些常用的机器学习算法。书中展示的算法涵盖了机器学习的各个重要领域:分类、聚类和投影。本书对一小部分算法进行了详细描述和推导,而不是简单地将大量算法罗列出来。 本书通过大量的MATLAB/Octave脚本将算法和概念由抽象的等式转化为解决实际问题的工具,利用它们读者可以重新绘制书中的插图,并研究如何改变模型说明和参数取值。......一起来看看 《机器学习基础教程》 这本书的介绍吧!