[英]Elasticsearch update document field value from interger to string
我有一个弹性搜索索引,其中一个字段与关键字的数据类型映射,这意味着字段将接受所有数据类型因此,我已将字符串和 integer 值接收到弹性搜索索引的同一字段中
现在,我想将所有 integer 值更新为字符串
例如:文件
{
"_index": "my-index",
"_type": "my_index_doc",
"_id": "PqLbOW4BtJ-51rS9hMsm",
"_score": null,
"_source": {
"user_id": 1019407,
},
"sort": [
1572928717850
]
}
所以我想将 user_id 字段为 integer 的所有文档数据更改为字符串,如下所示
预期文件:
{
"_index": "my-index",
"_type": "my_index_doc",
"_id": "PqLbOW4BtJ-51rS9hMsm",
"_score": null,
"_source": {
"user_id": "1019407",
},
"sort": [
1572928717850
]
},
我们可以对所有文档/任何其他解决方案使用弹性搜索更新查询吗?
如有错误请见谅。
提前致谢
您可以利用查询更新 API来实现此目的。 简单地运行这个:
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.