_update_by_query with substring

Hi
I wand to update specific fields with its substring value
MSISDN: "444123456"
replace with
MSISDN: "123456"

is there a way how to write update query ?
What is the best way to do such thing.

thank you
P

POST test_index/_update_by_query
{
  "script": {
    "source":"""
        ctx._source.MSISDN = substring(ctx._source.MSISDN,4,12);
        """,
    "lang": "painless"
  },
  "query": {
    "prefix": {"MSISDN": {"value": "444"}}
  }
}

Think you are looking for this.

ctx._source.MSISDN = ctx._source.MSISDN.substring(3, 9);

1 Like

Great this is exactly what I was looking for. Thank you such a fast response.

Do you have any tip where to start with coding more complex scripts in painless?

I learn best by watching video tutorials. Painless is Java (for the most part).

A free course on Java on YouTube is where I would go to start.

1 Like

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