60

我尝试通过 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] 主未分配 post api]","status":409}{"error":"ElasticSearchIllegalArgumentException[无法更新非动态设置[[index.analysis.filter.ar_stemmer.名称,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,索引。 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}

4

3 回答 3

152

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

关闭索引

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'
于 2013-11-04T11:02:55.737 回答
12

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

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

于 2014-06-25T16:47:18.817 回答
4

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

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

于 2020-04-02T07:00:19.797 回答