Search code examples
elasticsearch

how to do null value mapping in Elastic for existing fields


I have previously created an index on which I want add null value property:

PUT /check_test-1/_mapping
{  "properties": {
    "name": {
      "type": "keyword",
      "null_value":"N/A"
    }}}

EXISTING INDEX:

{ "check_test-1" : {
"mappings" : {
  "properties" : {
    "name" : {
      "type" : "keyword"
    },
    "status_code" : {
      "type" : "keyword",
      "null_value" : "N/A"
    }
  }
}}}

when I run the above query it gives this error:

 "type" : "illegal_argument_exception",
    "reason" : "Mapper for [name] conflicts with existing mapper:\n\tCannot update parameter [null_value] from [null] to [N/A]"

Index created using below query:

PUT /check_test-1/
{
  "mappings": {
    "properties": {
      "name": {
        "type": "keyword"
      },
      "status_code": {
        "type": "keyword",
        "null_value": "N/A"
      }
    }
  }
}

Elastic version 7.10.0


Solution

  • Like the message said, you cannot change an existing mapping of a field.

    Check the Elasticsearch documentation about mapping updates, especially

    If you need to change the mapping of a field in other indices, create a new index with the correct mapping and reindex your data into that index.