更改弹性搜索映射

change elasticsearch mapping

我正在尝试使用以下代码更改映射:

PUT /in_test/_mapping/keyword
{
 "properties" : {
            "term" : {
                "type" : "text",
                "index" : "not_analyzed" 
            }
        }
}

但是报错:

{
  "error": {
"root_cause": [
  {
    "type": "remote_transport_exception",
    "reason": "[tiebreaker-0000000000][172.17.0.24:19555][indices:admin/mapping/put]"
  }
],
"type": "illegal_argument_exception",
"reason": "Could not convert [term.index] to boolean",
"caused_by": {
  "type": "illegal_argument_exception",
  "reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
}
},
"status": 400
}

我也试过重建索引 通过:

PUT /in_test
 {
"mappings" : {
    "keyword" : {
        "properties" : {
            "term" : {
                "type" : "text",
                "index" : "not_analyzed" 
            }
        }
    }
}
}

但我得到了:

{
 "error": {
"root_cause": [
  {
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [keyword]: Could not convert [term.index] to boolean"
  }
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [keyword]: Could not convert [term.index] to boolean",
"caused_by": {
  "type": "illegal_argument_exception",
  "reason": "Could not convert [term.index] to boolean",
  "caused_by": {
    "type": "illegal_argument_exception",
    "reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
  }
}
 },
 "status": 400
 }

我也试过将 _type 更改为关键字,但仍然无效。 基本上,我想搜索字符串的精确匹配,为此我指的是:

https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html#_term_query_with_text

该文档页面来自 Elasticsearch 版本 2.X(见页面顶部),对于现代版本的 Elasticsearch 不再正确。

你得到的错误是因为 "index" 现在只接受 truefalse,并且指的是 属性 是否被索引 -由于您正在搜索 属性,您希望它是 true(默认值)。

相反,请尝试将类型设置为 "keyword",它不会被标记化。 https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-keyword-analyzer.html#_definition_5

PUT /in_test
{
"mappings" : {
    "keyword" : {
        "properties" : {
            "term" : {
                "type" : "keyword"
            }
        }
     }
}
}