Reputation: 530
I have an elastic search index where one of field is mapped with data type of keyword which means field will accept all data types So due to this, I have received string and integer values into same field of elastic search index
Now, I would like to update all integer values to string
Ex: Document
{
"_index": "my-index",
"_type": "my_index_doc",
"_id": "PqLbOW4BtJ-51rS9hMsm",
"_score": null,
"_source": {
"user_id": 1019407,
},
"sort": [
1572928717850
]
}
So I would like to change all documents data where user_id field is integer then its value to string as below
Expected Document:
{
"_index": "my-index",
"_type": "my_index_doc",
"_id": "PqLbOW4BtJ-51rS9hMsm",
"_score": null,
"_source": {
"user_id": "1019407",
},
"sort": [
1572928717850
]
},
Can we do it with elastic search update query for all documents / any other solution?
Excuse if any mistakes.
Thanks in advance
Upvotes: 2
Views: 1998
Reputation: 217304
You can leverage the Update by Query API to achieve this. Simply run this:
POST my-index/_update_by_query
{
"script": {
"source": "ctx._source.user_id = Integer.toString(ctx._source.user_id);",
"lang": "painless"
},
"query": {
"match_all": {}
}
}
Upvotes: 3