Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch update mapping conflict exception

I have an index named "myproject-error-2016-08" which has only one type named "error".

When I hit :

GET myproject-error-2016-08/_mapping

It returns following result:

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

I need to update the responseCode to not_analyzed, hence I am using following following reuest :

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

And getting following exception :

{
   "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
}

I have also tried following:

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

But it returned the same response.

Elastic Search is :

$ ./elasticsearch -version
Version: 2.3.5, Build: 90f439f/2016-07-27T10:36:52Z, JVM: 1.8.0_91
like image 981
Anil Bharadia Avatar asked Aug 22 '16 11:08

Anil Bharadia


People also ask

Can we update mapping in Elasticsearch?

If the Elasticsearch security features are enabled, you must have the manage index privilege for the target data stream, index, or alias. [7.9] If the request targets an index or index alias, you can also update its mapping with the create , create_doc , index , or write index privilege.

How do you fix a mapping conflict in Kibana?

Kibana mapping conflicts occur when the fields don't match the type saved in the index pattern. This can be fixed by updating the index pattern field list. Kibana >> Management >> Index patterns. Then click on the rotating arrows in the top right corner.

How do I change the mapping type in Elasticsearch?

It is not possible to update the mapping of an existing field. If the mapping is set to the wrong type, re-creating the index with updated mapping and re-indexing is the only option available. In version 7.0, Elasticsearch has deprecated the document type and the default document type is set to _doc.


1 Answers

You cannot change the type of a field once it's been created.

However, you can definitely create a not_analyzed sub-field like this:

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

Then you'll need to re-index your data/logs in order to populate that sub-field and you'll be able to reference responseCode.raw in your queries.

UPDATE: Since ES5 not_analyzed string do not exist anymore and are now called keyword:

PUT myproject-error-2016-08/_mapping/error
{
   "properties": {
      "responseCode": {
         "type": "text",
         "fields": {
            "raw": {
               "type": "keyword"
            }
         }
      }
   }
}
like image 68
Val Avatar answered Nov 15 '22 05:11

Val