内容简介:项目中使用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聚合返回的不正确的问题》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 监控聚合器系列之: open-falcon新聚合器polymetric
- elasticsearch学习笔记(七)——快速入门案例实战之电商网站商品管理:嵌套聚合,下钻分析,聚合分析
- mongodb高级聚合查询
- MongoDB聚合(aggregate)
- mongodb 聚合管道
- MongoDB指南---16、聚合
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
指数型组织
萨利姆•伊斯梅尔 (Salim Ismail)、迈克尔•马隆 (Michael S. Malone)、尤里•范吉斯特 (Yuri van Geest) / 苏健 / 浙江人民出版社 / 2015-8-1 / CNY 69.90
《指数型组织》是一本指数级时代企业行动手册。作者奇点大学创始执行理事萨利姆·伊斯梅尔归纳了指数型组织的11个强大属性,并提出了建立指数型组织的12个关键步骤。通过自己创建的一套“指数商”测试题,伊斯梅尔还测量出了指数型组织世界100强。 为什么小米、海尔和阿里巴巴能进入“指数型组织世界100强”名单?“独角兽”Uber、Airbnb、谷歌等知名企业是如何指数化自己的组织的? 未......一起来看看 《指数型组织》 这本书的介绍吧!