改变elasticsearch mapping

时间:2018-03-30 02:16:22

标签: elasticsearch 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

1 个答案:

答案 0 :(得分:1)

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

您获得的错误是因为" index"现在只接受truefalse,并且指的是该属性是否已被编入索引 - 因为您要通过此属性进行搜索,所以您希望它属于true(默认)。

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

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