尝试更新设置时出错

Rac*_*naa 47 elasticsearch

我尝试通过bash脚本执行此命令,但我收到以下错误:

#!/bin/bash 

curl -XPOST 'localhost:9200/my_index/_close' 

curl -XPUT 'localhost:9200/my_index/_settings' -d '{ 
 "analysis": { 
    "analyzer": { 
      "ar_analyzer": { 
        "tokenizer": "standard", 
        "filter" : ["standard", "lowercase", "synonym", "ar_stemmer"] 
      }, 
      "fr_analyzer": { 
        "tokenizer": "standard", 
        "filter" : ["standard", "lowercase", "synonym", "fr_stemmer"] 
      } 
    }, 
    "filter" : { 
      "ar_stemmer" : { 
          "type" : "stemmer", 
          "name" : "arabic" 
      }, 
      "fr_stemmer" : { 
          "type" : "stemmer", 
          "name" : "french" 
      }, 
      "synonym" : { 
          "type" : "synonym", 
          "synonyms_path" : "synonyms.txt" 
      } 
    } 
  } 
}' 

curl -XPOST 'localhost:9200/my_index/_open' 
Run Code Online (Sandbox Code Playgroud)

错误堆栈跟踪:

{"error":"IndexPrimaryShardNotAllocatedException [[my_index] primary not allocated post api]","status":409} {"error":"ElasticSearchIllegalArgumentException [无法更新非动态设置[[index.analysis.filter.ar_stemmer. name,index.analysis.analyzer.fr_analyzer.filter.3,index.analysis.filter.synonym.type,index.analysis.analyzer.ar_analyzer.filter.0,index.analysis.analyzer.fr_analyzer.filter.0,index. analysis.analyzer.ar_analyzer.filter.1,index.analysis.analyzer.fr_analyzer.filter.2,index.analysis.analyzer.fr_analyzer.filter.1,index.analysis.analyzer.ar_analyzer.filter.2,index.analysis. analyzer.ar_analyzer.filter.3,index.analysis.filter.ar_stemmer.type,index.analysis.filter.fr_stemmer.name,index.analysis.analyzer.ar_analyzer.tokenizer,index.analysis.filter.fr_stemmer.type,index.analysis.analyzer.fr_analyzer.tokenizer,index.analysis.filter.synonym.synonyms_path]]用于开放索引[[my_index]]]","status":400}

Waq*_*med 121

嗨,我正在使用这样的设置可能会帮助你:

关闭索引

curl -XPOST 'localhost:9200/lookupindex/_close'
Run Code Online (Sandbox Code Playgroud)

更新设置

curl -XPUT 'localhost:9200/lookupindex/_settings' -d '{
    "index": {
        "analysis": {
            "analyzer": {
                "custom_standard_analyzer": {
                    "type": "custom",
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "asciifolding",
                        "customstopwords"
                    ]
                },
                "phonetic_analyzer": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase",
                        "asciifolding",
                        "phoneticstopwords"
                    ]
                }
            },
            "filter": {
                "customstopwords": {
                    "type": "stop",
                    "stopwords": [
                        "+",
                        ".",
                        " ",
                        "ca",
                        "fl",
                        "bc",
                        "b.c",
                        "b.c.e",
                        "bce",
                        "act.c.",
                        "act",
                        "style",
                        "style of",
                        "attr.",
                        "attr",
                        "manner of",
                        "manner",
                        "circle of",
                        "circle",
                        "after",
                        "near",
                        "copy",
                        "copy after",
                        "imitator",
                        "school, copy",
                        "studio",
                        "studio of",
                        "Italian school",
                        "workshop of",
                        "workshop",
                        "16th",
                        "or",
                        "17th c.",
                        "late follower",
                        "follower of",
                        "follower",
                        "attributed",
                        "near",
                        "copy after painting",
                        "by or after",
                        "fake",
                        "and school",
                        "workshop-copy",
                        "counterproof",
                        "copy after drawing",
                        "copy of",
                        "school of",
                        "called",
                        "copy IBS",
                        "German School",
                        "placed with",
                        "attribution"
                    ]
                },
                "phoneticstopwords": {
                    "type": "stop",
                    "stopwords": [
                        "+",
                        ",",
                        "-",
                        ".",
                        "ca",
                        "fl",
                        "bc",
                        "b.c",
                        "b.c.e",
                        "bce",
                        "act.c.",
                        "act",
                        "style",
                        "style of",
                        "attr.",
                        "attr",
                        "manner of",
                        "manner",
                        "circle of",
                        "circle",
                        "after",
                        "near",
                        "copy",
                        "copy after",
                        "imitator",
                        "school, copy",
                        "studio",
                        "studio of",
                        "Italian school",
                        "workshop of",
                        "workshop",
                        "16th",
                        "or",
                        "17th c.",
                        "late follower",
                        "follower of",
                        "follower",
                        "attributed",
                        "near",
                        "copy after painting",
                        "by or after",
                        "fake",
                        "and school",
                        "workshop-copy",
                        "counterproof",
                        "copy after drawing",
                        "copy of",
                        "school of",
                        "called",
                        "copy IBS",
                        "German School",
                        "placed with",
                        "attribution"
                    ]
                }
            }
        }
    }
}
'  
Run Code Online (Sandbox Code Playgroud)

完成后重新打开索引

curl -XPOST 'localhost:9200/lookupindex/_open'
Run Code Online (Sandbox Code Playgroud)

  • 正确,您无法更改实时索引上的分析器.您需要将其关闭并在之后重新打开. (11认同)
  • @SanjeevKumarDangi通常的痛苦...用新设置创建新索引,reindex doc,更新别名 (6认同)
  • 只是好奇人们如果需要,人们如何在生产中做到这一点?那里你不能关闭索引. (4认同)

Mik*_*bov 10

我有类似的例外.你的榜样完整吗?你在关闭之前创建索引吗?

在我的情况下,它是如下:"创建索引,关闭它,添加设置,添加其他设置,添加映射,打开索引".索引创建后等待大约1秒修复了异常.

  • ES 客户端为此提供了一个 API,类似于 C# `client.ClusterHealth(x => x.WaitForStatus(WaitForStatus.Green));` 中的内容,这样您就不需要等待任意数字 (2认同)