由于无法摆脱它,我坚持使用ElasticSearch版本6.8.6
我想知道属于某一特定类别的文档数量。
所以我有一个聚合查询
我有一个值数组的映射
"categoryValues":{"type":"keyword"}我有一个问题
{
"_source": {
"excludes": ["content", "categoryValues", "categories"]
},
"query": {
"bool": {
"must": [{
"terms": {
"categoryValues.keyword": ["5aeb3714-6599-461c-9644-c3dfe12da513", "db87a0e5-2b67-430c-8c6b-5dac5ebe1883"]
}
}]
}
},
"highlight": {
"fields": {
"content": {}
}
},
"size": 0,
"aggs": {
"categories": {
"terms": {
"field": "categoryValues.keyword",
"size": 642
}
}
}
}aggs的大小很大,因为我们需要
正如您所看到的,我正在搜索两个关键字值
["5aeb3714-6599-461c-9644-c3dfe12da513", "db87a0e5-2b67-430c-8c6b-5dac5ebe1883"]然而,我的结果返回3
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"aggregations": {
"categories": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [{
"key": "3b93a7af-282b-4689-8f23-884891a9cd26",
"doc_count": 2
}, {
"key": "5aeb3714-6599-461c-9644-c3dfe12da513",
"doc_count": 1
}, {
"key": "db87a0e5-2b67-430c-8c6b-5dac5ebe1883",
"doc_count": 1
}]
}
}
}密钥"3b93a7af-282b-4689-8f23-884891a9cd26“在那里做什么?这是一个ElasticSearch错误吗?或者我的查询做错了--我不明白我怎么可能做错了,因为关键字搜索应该是准确的。
发布于 2020-09-16 21:07:38
因为categoryValues可以是一个数组,所以该数组的所有值都是聚合的,这就是为什么还会得到3b93a7af-282b-4689-8f23-884891a9cd26。查看doc_count (2),它可能包含在两个匹配的文档中。
您可以做的是在聚合响应中filter the values您想要看到的内容:
"aggs": {
"categories": {
"terms": {
"field": "categoryValues.keyword",
"size": 642,
"include": ["5aeb3714-6599-461c-9644-c3dfe12da513", "db87a0e5-2b67-430c-8c6b-5dac5ebe1883"]
}
}
}https://stackoverflow.com/questions/63920451
复制相似问题