ES 版本 - 7.17.7
我有一个索引,我对其运行聚合以获取与某些正则表达式匹配的所有字段。这应该不区分大小写,即
new york should match New York and NEW YORK and New YORK
在索引中添加了
lowercase_normaliser
,以便使用小写名称对文档进行索引。但这并不能解决问题。
现在我必须以小写形式传递正则表达式,否则它不会返回正确的结果。
我使用以下映射创建了一个名为 blah 的索引
{
"blah": {
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"raw": {
"type": "keyword",
"normalizer": "lowercase_normalizer"
}
}
}
}
}
}
}
索引设置-
{
"blah": {
"settings": {
"index": {
"max_ngram_diff": "20",
"analysis": {
"normalizer": {
"lowercase_normalizer": {
"filter": [
"lowercase"
],
"type": "custom"
}
}
}
}
}
}
}
插入的文件:
废话/_doc/1
{
"name": "NEW YORK"
}
废话/_doc/2
{
"name": "New Orleans"
}
废话/_doc/3
{
"name": "New Hampshire"
}
以下聚合查询未返回预期结果 - 查询
{
"aggregations": {
"autoComplete": {
"terms": {
"field": "name.raw",
"include": "New.*",
"order": [
{
"_term": "asc"
}
]
}
}
},
"size": 0
}
输出
"aggregations": {
"autoComplete": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
]
}
}
尝试搜索分析器。 有关更多详细信息,请点击此链接https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-analyzer.html