09.elasticsearch-analysis-normalizer應用

夜月行者發表於2020-10-19

1. 簡介

   normalizer和analyzer類似,不同的是normalizer 只會產出單個的token,所以normalizer 不包含tokenizer,只是由char_filter和token filter構成,因為normalnizer只會處理單個token,所以只有那些針對每個char工作的token filter是可以用來構建normalizer的,比如 lowercase filter是可以的,但是stemer filter則是不行的。

目前可以在normalizer中使用的filter有

arabic_normalization, 
asciifolding, 
bengali_normalization, 
cjk_width,
decimal_digit, 
elision, 
german_normalization,
 hindi_normalization,
indic_normalization,
lowercase, 
persian_normalization, 
scandinavian_folding, 
serbian_normalization, 
sorani_normalization, 
uppercase.

一個樣例


PUT index
{
  "settings": {
    "analysis": {
      "char_filter": {
        "quote": {
          "type": "mapping",
          "mappings": [
            "« => \"",
            "» => \""
          ]
        }
      },
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": ["quote"],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "foo": {
        "type": "keyword",
        "normalizer": "my_normalizer"
      }
    }
  }
}

相關文章