将分析器添加到elasticsearch中的现有索引6.3.1

l7mqbcuq  于 2023-01-16  发布在  ElasticSearch
关注(0)|答案(2)|浏览(141)

我正在尝试在elasticsearch中的现有索引中添加分析器。

以下是代码:-

curl -X POST "localhost:9200/existing_index_name/_mapping/_doc?pretty" -H 'Content-Type:     application/json' -d'
{
"settings":{
    "analysis":{
    "analyzer":{
    "analyzer_startswith":{
    "tokenizer":"keyword",
    "filter":["lowercase"]
     }
    }
   }      
  }
 }
'

下面是我得到的错误:-

["type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [settings : {analysis={analyzer={analyzer_startswith={tokenizer=keyword, filter=[lowercase]}}}}]"
inkz8wg9

inkz8wg91#

您需要调用_settings端点,而不是_mapping端点:

change this
                                                     |
                                                     v
curl -X POST "localhost:9200/existing_index_name/_settings?pretty" -H 'Content-Type: application/json' -d'{
  "analysis": {
    "analyzer": {
      "analyzer_startswith": {
        "tokenizer": "keyword",
        "filter": [
          "lowercase"
        ]
      }
    }
  }
}

不过,请注意,您需要首先关闭索引:

curl -XPOST http://localhost:9200/existing_index_name/_close

然后在更新设置后,您需要再次打开它

curl -XPOST http://localhost:9200/existing_index_name/_open
vs91vp4v

vs91vp4v2#

必须先关闭索引 curl -XPOST“http://localhost:9200/indexname/_close”
然后在curl中将Map更改为设置

curl -XPUT "http://localhost:9200/indexname/_settings" -H 'Content-Type: application/json' -d'
{
  "analysis": {
    "analyzer": {
      "analyzer_startswith": {
        "tokenizer": "keyword",
        "filter": [
          "lowercase"
        ]
      }
    }
  }
}'

要打开索引 curl -XPOST“http://localhost:9200/indexname/_open”

相关问题