Update one entry in an array

Using ES 5.6.3:

I am trying to update only one entry in an array.
For Example:
"myArray":[
"entry1",
"entry2"
]

I am trying to change the entry2 entry to entry3 and leave entry1 alone.
If I use
{"script": { "inline": "ctx_source.myArray = ['entry3']", "query": {"term": {"myArray":"entry2"}}}

It sets the entire array to entry3 and removes the entry1 item from the array.

Any example I can find only addresses objects in an array where an entire field is changed.

try, ctx._source.myArray.set(1, 'entry3') or call ctx._source.myArray.remove('entry2');ctx._source.myArray.add('entry3')

--Alex

Thanks for your help!

I got it to work with
int x = ctx._source.myArray.indexOf('entry2');
ctx._source.myArray.set(x,'entry3');

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