【发布时间】:2021-08-31 10:33:07
【问题描述】:
我们要求区分不区分大小写的字段(例如“CIty”和“ciTy”必须在一个组中)。 我可以在 Elasticsearch 中通过此功能实现查询吗?
【问题讨论】:
-
请提供足够的代码,以便其他人更好地理解或重现问题。
标签: elasticsearch distinct case-sensitive
我们要求区分不区分大小写的字段(例如“CIty”和“ciTy”必须在一个组中)。 我可以在 Elasticsearch 中通过此功能实现查询吗?
【问题讨论】:
标签: elasticsearch distinct case-sensitive
这个问题需要在索引时解决。使用normalizer进行索引时可以将标记转换为小写
{
"settings": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"city": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
}
}
}
}
会给
"aggregations" : {
"cities" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "a",
"doc_count" : 2
}
]
}
}
“A”和“a”都被视为单个值
【讨论】: