【问题标题】:set default analyzer of index设置索引的默认分析器
【发布时间】:2016-04-25 23:33:50
【问题描述】:

首先我想设置 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
}

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

【问题讨论】:

    标签: elasticsearch elasticsearch-plugin


    【解决方案1】:

    您就快到了,只是在您的路径中缺少/_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'
    

    【讨论】:

    • 我输入了和你一样的命令,然后得到错误信息: { "error" : { "root_cause" : [ { "type" : "invalid_type_name_exception", "reason" : "mapping type name [settings] 不能以 '' 开头" } ], "type" : "mapper_parsing_exception", "reason" : "mapping [settings]", "caused_by" : { "type" : "invalid_type_name_exception", "reason" : "mapping type name [_settings] can't start with ''" } }, "status" : 400 } 也许你想让我输入:
    • curl -XPOST localhost:9200/test/?pretty -d '{ "settings":{"analysis": { "analyzer" : { "default" : { "type" : "ik" } } } } }}' 但是
    • 对不起,我的错。您需要先关闭索引,然后命令然后重新打开索引。你也是PUT 而不是POST。那可行。另请注意,ik 分析器必须已经存在,否则将无法工作。
    • curl -XPOST localhost:9200/test/?pretty -d '{ "settings":{"analysis": { "analyzer" : { "default" : { "type" : "ik" } } } } }}' 但收到与我上面问题中的消息相同的错误消息。 (很抱歉我不知道如何在评论中使用降价。如果我明白了,我会编辑我的评论以便于阅读)
    • 查看我的答案并准确复制您在那里看到的内容。您的评论没有考虑我的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 2013-09-15
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多