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统计的数据范围不是查询后的结果,不知道原因出在哪里
条件应该放到must上
must不能满足搜索的要求
把所有条件放到一个must里这样可以解决
猜测有部分删除数据,虽然被删除了,但是没有被es的垃圾处理处理掉,导致加载到了聚合结果中