Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Elastic update_by_query inside array

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

POST index/_update_by_query
{
  "script": {
    "source": "ctx._source.dateCreated='2023-07-12'",
    "lang": "painless"
  },
  "query": {
    "terms": {
      "_id": [
"12345"
]
    }
  }
}

>Solution :

You can do it like this by accessing the array:

ctx._source.sources[0].postedDate='2023-07-12'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading