首页 新闻 搜索 专区 学院

elasticsearch7.x 聚合问题

0
悬赏园豆:10 [已解决问题] 解决于 2021-05-11 11:52

ES在查询完数据聚合时发现一个问题

{
"took" : 115,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 340393,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"group_by_products" : {
"value" : 344843
}
}
}
聚合后的数344843居然比查出来的总数340393还要大,不知道什么原因

{
"track_total_hits": true,
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"delflag": {
"value": "0"
}
}
}
],
"should": [
{
"match": {
"product_name": {
"query": "acid",
"fuzziness": "1",
"prefix_length": 2,
"boost": 5
}
}
},
{
"match": {
"cas_no": {
"query": "acid",
"fuzziness": "1",
"prefix_length": 2,
"boost": 3
}
}
},
{
"match": {
"molecular_formula": {
"query": "acid",
"fuzziness": "1",
"prefix_length": 2,
"boost": 2
}
}
},
{
"nested": {
"path": "other_name",
"query": {
"match": {
"other_name.name": {
"query": "acid",
"fuzziness": "1",
"prefix_length": 2,
"boost": 4
}
}
}
}
}
]
}
},
"collapse": {
"field": "products_id"
},
"_source": {
"excludes": [
"create_by",
"update_by",
"del_date",
"delflag",
"update_date",
"create_date"
]
},
"aggs": {
"group_by_products": {
"cardinality": {
"field": "products_id"
}
}
}
}
难道cardinality统计的数据范围不是查询后的结果,不知道原因出在哪里

kakaok的主页 kakaok | 初学一级 | 园豆:92
提问于:2021-05-07 11:46
< >
分享
最佳答案
0

条件应该放到must上

收获园豆:10
beetlex | 菜鸟二级 |园豆:247 | 2021-05-07 19:15

must不能满足搜索的要求

kakaok | 园豆:92 (初学一级) | 2021-05-08 09:26


把所有条件放到一个must里这样可以解决

kakaok | 园豆:92 (初学一级) | 2021-05-11 11:51
其他回答(1)
0

猜测有部分删除数据,虽然被删除了,但是没有被es的垃圾处理处理掉,导致加载到了聚合结果中

写爬虫的后端是好前端 | 园豆:204 (菜鸟二级) | 2021-05-10 17:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册