在数组内进行Elasticsearch的update_by_query操作

huangapple go评论146阅读模式
英文:

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'

huangapple
  • 本文由 发表于 2023年8月10日 17:00:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定