es ik 分詞 5.x后,設置默認分詞


1.使用模板方式,設置默認分詞

注: 設置模板,需要重新導入數據,才生效

通過模板設置全局默認分詞器

curl -XDELETE http://localhost:9200/_template/rtf


curl -XPUT http://localhost:9200/ _template/rtf
-d'
{
  "template":   "*", 
  "settings": { "number_of_shards": 1 }, 
  "mappings": {
    "_default_": {
      "_all": { 
        "enabled": true
      },
      "dynamic_templates": [
        {
          "strings": { 
            "match_mapping_type": "string",
            "mapping": {
              "type": "text",
              "analyzer":"ik_max_word",
              "ignore_above": 256,
              "fields": {
                "keyword": {
                  "type":  "keyword"
                }
              }
            }
          }
        }
      ]
    }
  }
}
'

2.單個設置分詞(github上的例子)

curl -XPOST http://localhost:9200/index/fulltext/_mapping -H 'Content-Type:application/json' -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }

}'
curl -XPOST http://localhost:9200/索引/類型/_mapping -H 'Content-Type:application/json' -d'
{
        "properties": {
            "字段": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }

}'

注: 設置如果 遇到 

            {
                "type": "illegal_argument_exception",
                "reason": "Mapper for [content] conflicts with existing mapping in other types:\n[mapper [content] has different [analyzer]]"
            }

從錯誤提示上來看是說要創建的映射已經存在了,問題的關鍵就在於我沒有創建過叫index的索引

解決:重新導入數據,不做查詢的情況下(查詢了的話,會默認創建一個mapping),設置_mapping

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM