代码之家  ›  专栏  ›  技术社区  ›  iurti

设置索引的默认分析器

  •  10
  • iurti  · 技术社区  · 9 年前

    首先,我想设置ES的默认分析器,但失败了。然后根据其他问题和网站,我尝试设置一个索引的默认分析器。但也存在一些问题。

    我已经配置了ik分析器,我可以设置一些字段的分析器,这是我的命令:

    curl -XPUT localhost:9200/test

    curl -XPUT localhost:9200/test/test/_mapping -d'{
     "test":{
       "properties":{
         "name":{
           "type":"string",
           "analyzer":"ik"
         }
       }
     }
    }'
    

    并得到消息:

    {"acknowledged":true}
    

    而且,这也是我的愿望。

    但是,如果我尝试设置索引的默认分析器:

    curl -XPOST localhost:9200/test1?pretty -d '{                                                                           "index":{
    "analysis" : {
                "analyzer" : {
                    "default" : {
                        "type" : "ik"
                    }
                }
            }
        }
    }'
    

    我将收到错误消息:

    {
      "error" : {
        "root_cause" : [ {
          "type" : "index_creation_exception",
          "reason" : "failed to create index"
        } ],
        "type" : "illegal_argument_exception",
        "reason" : "no default analyzer configured"
      },
      "status" : 400
    }
    

    真奇怪,不是吗? 期待您对这个问题的意见。谢谢!:)

    1 回复  |  直到 9 年前
        1
  •  10
  •   Val    9 年前

    你快到了,你只是错过了 /_settings 在你的道路上。改为这样做。还要注意,您需要 close the index first 然后在更新分析器后重新打开它。

    // close index
    curl -XPOST 'localhost:9200/test1/_close'
    
                                add this to the path
                                         |
                                         v
    curl -XPUT localhost:9200/test1/_settings?pretty -d '{                                                                           "index":{
    "analysis" : {
                "analyzer" : {
                    "default" : {
                        "type" : "ik"
                    }
                }
            }
        }
    }'
    
    // re-open index
    curl -XPOST 'localhost:9200/test1/_open'