【发布时间】:2020-01-20 16:30:05
【问题描述】:
设置: Elasticsearch 6.3
我有一个代表产品目录的索引。
每个文档都包含一个产品的数据。
其中一个名为 categories 的字段是一个字符串数组 - 相关类别列表。
99.9% 的查询是:给我匹配类别 A、B 和 C 的产品。查询是 不区分大小写,因此类别映射如下:
"categories": {
"type": "keyword",
"normalizer": "lowercase_normalizer"
}
对于报告(占所有查询的 0.1%),我需要返回所有可能类别的列表 区分大小写!
考虑以下文件:
"_id": "product1",
"_source": {
"categories": [
"WOMEN",
"Footwear"
]
}
"_id": "product2",
"_source": {
"categories": [
"Men",
"Footwear"
]
}
运行以下查询:
{
"size": 0,
"aggs": {
"categories": {
"terms": {
"field": "categories",
"size": 100
}
}
}
}
返回:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 40453,
"max_score": 0,
"hits": [
]
},
"aggregations": {
"sterms#categories": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 12453,
"buckets": [
{
"key": "men",
"doc_count": 27049
},
{
"key": "women",
"doc_count": 21332
},
.........
]
}
}
}
有没有办法返回区分大小写的类别(存储在文档中)?我对这个查询结果中的["WOMEN", "Men"] 感兴趣。
The question in Elasticsearch discuss forum
谢谢, 伊泰
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation