Changing data type

Is there any workaround to change the datatype of a field without reindexing?

Nope.

for deleting a mapping and its documents?

Sorry?

i want to change the datatype of a field
Since i can't do that without reindexing, i thought that i could just drop the mapping and create a new one with the changes i need and then push the documents to the new mapping
is that possible?

Not unless you delete all the data as well.

Is there any reason why changing the field datatype isn't supported?
My index will contain a large volume of data which needs to be available at all times.
reindexing is an expensive operation and i just want to avoid or bypass it

This might not be usable at all since it seems like pretty bad practice but it might be of use to you :
Create a new field with the new dataType you want with the put mapping api :

PUT index/_mapping/type
{
  "properties": {
    "newField": {
      "type": "keyword"
    }
  }
}

And then run an update by query on the documents you want to have their field change :

POST index/type/_update_by_query
{
  "script": {
    "inline": "ctx._source.newField= ctx._source.oldFieldWithOtherDataType",
    "lang": "painless"
  },
  "query": {
    "match_all": {
    }
  }
}
1 Like

Yes. One of them is that elasticsearch/Lucene is using immutable files. What has been indexed will remain as it was when you indexed it which will lead to inconsistencies.
The only way to "regenerate" a new version of the Lucene files is to reindex.

3 Likes

Thanks Heinmci
but this doesn't solve my issue..

thanks guys for responding promptly
you've been of great help to me

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.