英文:
Elastic update_by_query inside array
问题
我有一个数组,看起来像这样:
"_source": {
"dateCreated": "2023-07-12",
"sources": [
{
"1": null,
"lastUpdateDate": "2023-08-10T11:12:36.9848505",
"postedDate": "2023-08-10T10:38:57.9440773"
}
]
}
如何更新来源数组中的postedDate?
我已经成功使用以下查询来更新dateCreated:
POST index/_update_by_query
{
"script": {
"source": "ctx._source.dateCreated='2023-07-12'",
"lang": "painless"
},
"query": {
"terms": {
"_id": [
"12345"
]
}
}
}
英文:
I have an array which looks like this:
"_source": {
"dateCreated": "2023-07-12",
"sources": [
{
"1": null,
"lastUpdateDate": "2023-08-10T11:12:36.9848505",
"postedDate": "2023-08-10T10:38:57.9440773"
How can I update postedDate from sources array?
I've managed to update dateCreated with this query:
POST index/_update_by_query
{
"script": {
"source": "ctx._source.dateCreated='2023-07-12'",
"lang": "painless"
},
"query": {
"terms": {
"_id": [
"12345"
]
}
}
}
答案1
得分: 0
ctx._source.sources[0].postedDate='2023-07-12' 可以这样做,通过访问数组:
英文:
You can do it like this by accessing the array:
ctx._source.sources[0].postedDate='2023-07-12'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论