Changing data type

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