[英]Elasticsearch update document field value from interger to string
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我有一个弹性搜索索引,其中一个字段与关键字的数据类型映射,这意味着字段将接受所有数据类型因此,我已将字符串和 integer 值接收到弹性搜索索引的同一字段中
Now, I would like to update all integer values to string现在,我想将所有 integer 值更新为字符串
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所以我想将 user_id 字段为 integer 的所有文档数据更改为字符串,如下所示
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提前致谢
You can leverage the Update by Query API to achieve this.您可以利用查询更新 API来实现此目的。 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": {}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.