Elasticsearch:搜索忽略大小写和重音的关键字(通过聚合)

Elasticsearch: Search in keywords ignoring case and accent (via aggregation)

我可以像这样在索引上搜索特定关键字:

GET */_search/?
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "TECH.keyword": {
      "terms": {
        "field": "TECH.keyword",
        "include": ".*mine.*",
        "order": {
          "_count": "desc"
        },
        "size": 20
      }
    }
  }
}

使用此查询,我可以获得所有 TECH.keyword 字段中包含 "mine" 的条目,按 "_count": "desc" 排序。所以,没关系。

实际问题是索引可以在TECH.keyword字段中包含mineMineMINE甚至miné。我想return全部。

有没有忽略大小写和重音的关键字搜索方法?

当前映射为:

"TECH": {
  "type": "text",
  "fields": {
    "keyword": {
      "type": "keyword",
      "ignore_above": 256
    }
  }
},

您应该可以使用 normalizer 完成此操作。您不能在 keyword 字段上使用 analyzer,但可以使用 normalizer。它允许您使用 lowercaseasciifolding.

https://www.elastic.co/guide/en/elasticsearch/reference/6.4/normalizer.html

PUT index
{
  "settings": {
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  },
  "mappings": {
    "_doc": {
      "properties": {
        "foo": {
          "type": "keyword",
          "normalizer": "my_normalizer"
        }
      }
    }
  }
}