normalizer(归一化)

keyword fields(关键字字段) 的 normalizer(归一化)属性与 analyzer分析器)类似,只不过它保证 analysis chain(分析链)生成单一的 token(词元).

normalizer(归一化)应用于索引 keyword(关键字)之前,以及诸如在 matchquery(匹配查询),查询解析器搜索 keyword fields(关键字字段)的时候.

curl -XPUT 'localhost:9200/index?pretty' -H 'Content-Type: application/json' -d'
{
  "settings": {
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  },
  "mappings": {
    "type": {
      "properties": {
        "foo": {
          "type": "keyword",
          "normalizer": "my_normalizer"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/index/type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "foo": "BÀR"
}
'
curl -XPUT 'localhost:9200/index/type/2?pretty' -H 'Content-Type: application/json' -d'
{
  "foo": "bar"
}
'
curl -XPUT 'localhost:9200/index/type/3?pretty' -H 'Content-Type: application/json' -d'
{
  "foo": "baz"
}
'
curl -XPOST 'localhost:9200/index/_refresh?pretty'
curl -XGET 'localhost:9200/index/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "foo": "BAR"
    }
  }
}
'

上述查询与 documents(文档) 12相匹配,这是因为在索引和查询的时候都将 BAR转换为了 bar.

此外,keywords 在索引之前转换意味着聚合返回 normalised values(归一化的值):

返回

Last updated

Was this helpful?