elasticsearch更新映射冲突异常

标签 elasticsearch

我有一个名为“myproject-error-2016-08”的索引,它只有一种名为“error”的类型。

当我点击 :

GET myproject-error-2016-08/_mapping

返回结果如下:

{
   "myproject-error-2016-08": {
      "mappings": {
         "error": {
            "properties": {
               ...
               "responseCode": {
                  "type": "string"
               },
               ...
            }
         }
      }
   }
}

我需要将 responseCode 更新为 not_analyzed, 因此我使用以下请求:

PUT myproject-error-2016-08/_mapping/error
{
   "properties": {
      "responseCode": {
         "type": "string",
         "index": "not_analyzed"
      }
   }
}

并得到以下异常:

{
   "error": {
      "root_cause": [
         {
            "type": "illegal_argument_exception",
            "reason": "Mapper for [responseCode] conflicts with existing mapping in other types:\n[mapper [responseCode] has different [index] values, mapper [responseCode] has different [doc_values] values, cannot change from disabled to enabled, mapper [responseCode] has different [analyzer]]"
         }
      ],
      "type": "illegal_argument_exception",
      "reason": "Mapper for [responseCode] conflicts with existing mapping in other types:\n[mapper [responseCode] has different [index] values, mapper [responseCode] has different [doc_values] values, cannot change from disabled to enabled, mapper [responseCode] has different [analyzer]]"
   },
   "status": 400
}

我也试过以下:

PUT myproject-error-2016-08/_mapping/error?update_all_types
{
...
}

但它返回了相同的响应。

Elasticsearch 是:

$ ./elasticsearch -version
Version: 2.3.5, Build: 90f439f/2016-07-27T10:36:52Z, JVM: 1.8.0_91

最佳答案

cannot change the type一个字段一旦被创建。

但是,您绝对可以像这样创建一个 not_analyzed 子字段:

PUT myproject-error-2016-08/_mapping/error
{
   "properties": {
      "responseCode": {
         "type": "string",
         "fields": {
            "raw": {
               "type": "string",
               "index": "not_analyzed"
            }
         }
      }
   }
}

然后你需要re-index your data/logs为了填充该子字段,您将能够在查询中引用 responseCode.raw

更新:由于 ES5 not_analyzed string 不再存在,现在称为 keyword:

PUT myproject-error-2016-08/_mapping/error
{
   "properties": {
      "responseCode": {
         "type": "text",
         "fields": {
            "raw": {
               "type": "keyword"
            }
         }
      }
   }
}

关于elasticsearch更新映射冲突异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39077981/

相关文章:

java - 除非include_type_name设置为true,否则映射定义不能嵌套在类型[_doc]下

elasticsearch - 如何使用NEST客户端在一系列附件中使用附件处理器并删除处理器?

caching - RAM 数据存储中的 Elasticsearch

elasticsearch - 如何在 Elastic High Level Rest Client 中使用 search_after 进行分页

elasticsearch - 嵌套字段中的嵌套聚合?

elasticsearch - 在Nest 2.x中合并BoolQueryDescriptor

elasticsearch - 电话号码分析器

elasticsearch - Elasticsearch-用逗号分割-分割过滤器Logstash

elasticsearch - 如何匹配多个单词?

elasticsearch - Elasticsearch检查标题是否已在类型中使用