在数组内进行Elasticsearch的update_by_query操作

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

Elastic update_by_query inside array

问题

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

  1. "_source": {
  2. "dateCreated": "2023-07-12",
  3. "sources": [
  4. {
  5. "1": null,
  6. "lastUpdateDate": "2023-08-10T11:12:36.9848505",
  7. "postedDate": "2023-08-10T10:38:57.9440773"
  8. }
  9. ]
  10. }

如何更新来源数组中的postedDate?

我已经成功使用以下查询来更新dateCreated:

  1. POST index/_update_by_query
  2. {
  3. "script": {
  4. "source": "ctx._source.dateCreated='2023-07-12'",
  5. "lang": "painless"
  6. },
  7. "query": {
  8. "terms": {
  9. "_id": [
  10. "12345"
  11. ]
  12. }
  13. }
  14. }
英文:

I have an array which looks like this:

  1. "_source": {
  2. "dateCreated": "2023-07-12",
  3. "sources": [
  4. {
  5. "1": null,
  6. "lastUpdateDate": "2023-08-10T11:12:36.9848505",
  7. "postedDate": "2023-08-10T10:38:57.9440773"

How can I update postedDate from sources array?

I've managed to update dateCreated with this query:

  1. POST index/_update_by_query
  2. {
  3. "script": {
  4. "source": "ctx._source.dateCreated='2023-07-12'",
  5. "lang": "painless"
  6. },
  7. "query": {
  8. "terms": {
  9. "_id": [
  10. "12345"
  11. ]
  12. }
  13. }
  14. }

答案1

得分: 0

ctx._source.sources[0].postedDate='2023-07-12' 可以这样做,通过访问数组:

英文:

You can do it like this by accessing the array:

  1. 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:

确定