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

 

posted @ 2018-12-10 16:28  不烦~~!  阅读(2780)  评论(0编辑  收藏  举报