Codinggeek
Codinggeek

Reputation: 131

Do I need to reindex all older documents forcefully when mapping of any NON-INDEXED field is changed?

I have below mapping in my elastic search

"properties": {
  "id": {
    "type": "string",
    "index": "not_analyzed"
  },
  "tag": {
    "type": "long"
  },
  "level": {
    "type": "integer"
  },
  "fieldIn": {
    "type": "long",
    "index": "no"
  },
  "fieldOut": {
    "type": "long",
    "index": "no"
  },
  
}

I need to change the data type of fieldIn/fieldOut to String. As it is a NON-INDEXED , do i need to reindexed forcefully all the older documents

Upvotes: 1

Views: 64

Answers (1)

Amit
Amit

Reputation: 32376

You are changing the data-type of existing field which is a breaking change and Elastic will not allow to do that, Please follow the example I created to show you the MergeMappingException which ES will throw in your case.

Create index mapping with a long field:

{
  "mappings": {
    "mytype": {
      "properties": {
        "fieldOut": {
          "type": "long",
          "index": "no"
        }
      }
    }
  }
}

Index doc containing long values

{
 "fieldOut" :14897594242
}

{
 "fieldOut" :112343434534
}

** Try to change the fieldOut to string using the put aka update mapping API**

{
  "mytype": {
    "properties": {
      "fieldOut": {
        "type": "string", // note changed to string type
        "index": "no"
      }
    }
  }
}

This result in below exception:

{ "error": "MergeMappingException[Merge failed with failures {[mapper [fieldOut] of different type, current_type [long], merged_type [string]]}]", "status": 400 }

Upvotes: 1

Related Questions