Replace string in array with _update_by_query

Hello,

I'd like to replace string by another one in all Array elements but I don't know how to do that in Java.

My document is like :

 "pictures" : [
            "https://www.mydomain.com/images/123.png",
            "https://www.mydomain.com/images/456.png",
            "https://www.mydomain.com/images/789.png"
          ],

And I'd like to have:

    "pictures" : [
            "https://pictures.mydomain.com/123.png",
            "https://pictures.mydomain.com/456.png",
            "https://pictures.mydomain.com/789.png"
          ],

I guess it's something like that but for an array List

    POST myindex/_update_by_query
{
  "script": {
        "lang": "painless",
        "inline": "ctx._source.pictures = ctx._source.pictures.replace('https://www.mydomain.com/images/', 'https://pictures.mydomain.com/')"
    },
    "query": {
        "exists": {
            "field": "pictures"
        }
    }
}

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.