Update object array


(kmx) #1

Hi,
Im trying to update an item from this array :

myarray : [
{
id: 1,
valid: false
},
{
id: 23,
valid: false
},
{
id: 456,
valid: false
}
]

I would like to set 'valid' to 'true' for item with 'id' : 23

I tried using the 'script' query without success

How can i achieve that ?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/e96f11d3-75e0-4472-8f3f-b6a500aad712%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(kmx) #2

i found a way to do it after checking MVEL syntax:
...
script: "
foreach(item : ctx._source.myarray) {
if(item.id == 23) {
item.valid = true;
}
}
"
...

Can someone tell me if this is the proper way to do it ?

Le mardi 20 mai 2014 09:39:59 UTC+2, kmx a écrit :

Hi,
Im trying to update an item from this array :

myarray : [
{
id: 1,
valid: false
},
{
id: 23,
valid: false
},
{
id: 456,
valid: false
}
]

I would like to set 'valid' to 'true' for item with 'id' : 23

I tried using the 'script' query without success

How can i achieve that ?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9c7f6c5e-dd7c-47a4-b32c-92e20ffd31c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #3