Elasticsearch 拼音检索

Install

./bin/elasticsearch-plugin install \
https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.6.1/elasticsearch-analysis-pinyin-7.6.1.zip

重启 ES.

自定义 analyzer

DELETE /demo

PUT /demo
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_pinyin_analyzer": {
          "tokenizer": "ik_max_word",
          "filter": [
            "custom_pinyin_filter"
          ]
        }
      },
      "filter": {
        "custom_pinyin_filter": {
          "type": "pinyin",
          "keep_full_pinyin": true,
          "keep_joined_full_pinyin": true,
          "keep_original": true,
          "lowercase": true,
          "remove_duplicated_term": true,
          "keep_none_chinese": true,
          "keep_none_chinese_in_first_letter": true,
          "none_chinese_pinyin_tokenize": false
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "custom_pinyin_analyzer",
        "search_analyzer": "ik_smart"
      }
    }
  }
}
GET /demo/_analyze
{
  "analyzer": "pinyin",
  "text": ["小白 is a Dog. 他是最白的狗!"]
}

GET /demo/_analyze
{
  "analyzer": "custom_pinyin_analyzer",
  "text": ["小白 is a Dog. 他是最白的狗!"]
}

GET /demo/_analyze
{
  "analyzer": "ik_smart",
  "text": ["小白 is a Dog. 他是最白的狗!"]
}

GET /demo/_analyze
{
  "analyzer": "ik_smart",
  "text": ["xiaobai"]
}

GET /demo/_analyze
{
  "analyzer": "ik_max_word",
  "text": ["小白 is a Dog. 他是最白的狗!"]
}
POST /demo/_doc/1
{
  "content": "小白 is a Dog. 他是最白的狗!"
}

GET /demo/_search
{
  "query": {
    "match": {
      "content": "xiaobai"
    }
  }
}

https://github.com/medcl/elasticsearch-analysis-pinyin

你可能感兴趣的:(Elasticsearch 拼音检索)