Convert the long datatype field to string


(Rajesh Kumar) #1

I am looking for an example, to convert the data type of field in the document from long to string.
could you anyone please help me on this.


(Alexander Reelsen) #2

You need to reindex your data, as the internal data structure used to store a long differs from the one storing a string.

Check out the Reindex API, which can help you to execute the reindexing, once you have changed your mapping properly in your new index.


(Rajesh Kumar) #3

First of all thanks for the reply.

I am OK, to do the reindex. But I am not to specify the datatype change in the new index, i have tried with below example. it was not working. still the new index has the data type long only.

POST _reindex?pretty
{
  "source": {
    "index": "index1.1526279922.1"
  },
  "dest": {
    "index": "index1.string.1"
  },
  "script": {
    "inline": "ctx._source.inode = String.valueOf(ctx._source.inode)"
  }
}

Please correct me, if i am doing anything wrong here.


(Alexander Reelsen) #4

You need to create the proper mapping before you start indexing documents. See our mapping documentation.

See reindex API docs also state this in the first paragraph.


(Rajesh Kumar) #5

Finally, I got the solution. Thank you very much for your support.

Below is the same.

POST _reindex?pretty
{
  "source": {
    "index": "index1.1526279922.1"
  },
  "dest": {
    "index": "index1.string.1"
  },
  "script": {
    "source": "ctx._source.inode = '' + ctx._source.inode"
  }
}

(system) #6

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