51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

在数组内进行Elasticsearch的update_by_query操作

英文:

Elastic update_by_query inside array

问题 {#heading}

我有一个数组,看起来像这样:

"_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 {#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'

赞(1)
未经允许不得转载:工具盒子 » 在数组内进行Elasticsearch的update_by_query操作