Changing data type


(Chanakyan) #1

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


(Mark Walkom) #2

Nope.


(Chanakyan) #3

for deleting a mapping and its documents?


(Mark Walkom) #4

Sorry?


(Chanakyan) #5

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?


(Mark Walkom) #6

Not unless you delete all the data as well.


(Chanakyan) #7

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


(Heinmci) #8

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

(David Pilato) #9

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.


(Chanakyan) #10

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


(Chanakyan) #11

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


(system) #12

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