Hey
I figured it out, but it leads me on to another question.
So the way to execute a script over a list of elements is as follows:
PUT twitter/twit/1
{
"list": [
{
"tweet_id": "1",
"a": "b"
},
{
"tweet_id": "123",
"a": "f"
}
]
}
POST /twitter/twit/1/_update
{
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) { item['new_field'] = 'ghi'; } }",
"params": {
"tweet_id": "123"
}
}
My next question: how can I query the index to find all matching documents
with say "tweet_id": "123" and then execute the script on only those
documents?
When I tried
.. query..
{
"filter": {
"script": "foreach (item : ctx._source.list) {if (item['tweet_id'] ==
tweet_id) { item['new_field'] = 'ghi'; } }",
"params": {
"tweet_id": "123"
}
}
}
I got an error saying property : ctx : unresolvable
Thanks.
On Friday, August 29, 2014 10:33:23 AM UTC+1, [email protected] wrote:
>
> Hi
> Say I have a list of elements like this:
>
> PUT twitter/twit/1
> {
> "list": [
> {
> "a": "b",
> "c": "d",
> * "e": "f"*
> },
> {
> "1": "2",
> "3": "4"
> }
> ]
> }
>
> And I want to change the value of "e" (currently "f") to say "new_f " such
> that the document looks like:
>
> {
> "list": [
> {
> "a": "b",
> "c": "d",
> * "e": "new_f"*
> },
> {
> "1": "2",
> "3": "4"
> }
> ]
> }
>
> Is there a way to do this ? Maybe in MVEL ?
>
> Do I match on document
> {
> "a": "b",
> "c": "d",
> "e": "f"
> }
>
> ie if list.contains(document) { some kind of update; } // is this
> possible ?
>
>
> I know MVEL is being deprecated in 1.4 however it will do for now.
>
> I want to use bulk request.
>
> I know it's possible to remove the element like this:
> bulkRequestBuilder.setScript("if (ctx._source.list.contains(document))
> {ctx._source.list.remove(document)} }").setScriptParams etc
>
>
> but is it possible to "update" a field in the document also ?
>
> Thanks.
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/5c641a4e-a02f-4ebe-972f-cd2a320d15d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.