如何为同一文档复制对象中的两个字段。我在elasticsearch中有一个对象
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "AXWTrVr6LIkj1JVvPnDX",
"_score": 1,
"_source": {
"field1": 1,
"field2": 2
}
}
]
}
}
我希望将每个文档的field1
和field2
复制到test_object中。预期结果
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "AXWTrVr6LIkj1JVvPnDX",
"_score": 1,
"_source": {
"field1": 1,
"field2": 2,
"test_object":{
"field1": 1,
"field2": 2
}
}
}
]
}
}
我正在尝试通过下一个脚本来完成,但我不明白哪里出了问题
POST test_index/doc/update
{
"query":{
"match":{
"field1":1
}
},
"script" : {
"inline": "ctx._source.test_field.field1 = ctx._source.field1 ctx._source.test_field.field2 = ctx._source.field2"
}
}
发布于 2020-11-04 15:22:29
首先,你需要点击_update_by_query
endpoint
然后,由于文档中不存在test_field
,因此需要创建它:
这对你来说应该是可行的:
POST test_index/_update_byquery
{
"query":{
"match":{
"field1":1
}
},
"script" : {
"inline": "ctx._source.test_field = ['field1': ctx._source.field1, 'field2': ctx._source.field2]"
}
}
https://stackoverflow.com/questions/64682381
复制相似问题