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