【问题标题】:error when trying to update the settings尝试更新设置时出错
【发布时间】:2020-04-02 15:00:19
【问题描述】:

我尝试通过 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' 

错误堆栈跟踪:

{"error":"IndexPrimaryShardNotAllocatedException[[my_index] 主 未分配员额 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}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您好,我正在使用这样的设置可能对您有帮助:

    关闭索引

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

    更新设置

    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"
                        ]
                    }
                }
            }
        }
    }
    '  
    

    完成后重新打开索引

    curl -XPOST 'localhost:9200/lookupindex/_open'
    

    【讨论】:

    • 正确,您无法更改实时索引上的分析器。您需要先关闭它,然后再重新打开它。
    • 只是好奇如果需要,人们在生产中是如何做到的?在那里你不能关闭索引。
    • @SanjeevKumarDangi 常见的痛苦......使用新设置创建新索引,重新索引文档,更新别名
    • 有些人做索引别名。客户端始终使用别名进行摄取。所以你可以创建一个新的索引并手动戳它的设置。然后将别名移动到新索引(移动是原子的)。
    【解决方案2】:

    我也有类似的例外。你的例子完整吗?您是否在关闭索引之前创建索引?

    在我的例子中是这样的:“创建索引,关闭它,添加设置,添加其他设置,添加映射,打开索引”。索引创建后等待大约 1 秒修复了异常。

    【讨论】:

    • 在创建索引和关闭索引之间等待 1 秒以更新设置解决了问题。谢谢
    • ES 客户端为此提供了一个 API,类似于 C# client.ClusterHealth(x => x.WaitForStatus(WaitForStatus.Green)); 中的内容,这样您就无需等待任意数字
    【解决方案3】:

    对于使用 AWS Elastic-search 服务的人,关闭和打开是不允许的,他们需要按照这里提到的重新索引。

    基本上使用当前原始索引的所有映射创建一个临时索引并添加/修改这些映射和设置(分析器所在的位置),删除原始索引并使用该名称创建一个新索引并从临时索引复制回所有映射和设置.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 2014-12-08
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多