Hey 

*I figured it out, I am able to update but I am not able to remove object 
that satisfies the condition*

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"
  }
}
*this is working*

*for remove i am doing this*

POST /twitter/twit/1/_update
{
  "script": "foreach (item : ctx._source.list) {if (item['tweet_id'] == 
tweet_id) {ctx._source.list.remove(item);  }  }",
  "params": {
    "tweet_id": "123"
  }
}


*but this is not working and giving this error, *

ElasticsearchIllegalArgumentException[failed to execute script]; nested: 
ConcurrentModificationException; 
Error: ElasticsearchIllegalArgumentException[failed to execute script]; 
nested: ConcurrentModificationException; 
..................................
...............................


*please help........*




On Wednesday, April 10, 2013 12:22:14 PM UTC+5:30, Andrei Tolnai wrote:
>
> Hello.
>
> I use *Elastic Search Java API *for basic *CRUD *operations on ES 
> documents; with *root type* documents it is working fine.
>
> However when I want to delete a nested document, I don't know how to use 
> the *Java API* and scripting that *Elastic Search *provides.
>
> I have the following *root type* document which has in it a nested *users 
> *property (nested document).
> {
>    "customer":
>       {
>          "_all" : {"enabled" : false},
>          "_source" : {"enabled" : true},
>          "store" : "true",
>          "properties":
>             {
>                "location" : { "type": "string", "store": "yes", 
> "index":"not_analyzed" },
>                "comments" : { "type": "string", "store": "yes", 
> "index":"not_analyzed" },
>               * "users":*
> *                  {*
> *                     "type":"nested",*
> *                     "store":"yes", *
> *                     "properties":*
> *                        {*
> *                           "_id" : { "type":"string", "store":"yes", 
> "index":"not_analyzed" },*
> *                           "name" : { "type":"string", "store":"yes", 
> "index":"not_analyzed" },*
> *                           "birthDate" : { "type":"date", "store":"yes", 
> "index":"not_analyzed" }*
> *                        }*
> *                  }*
>             }
>       }
> }
>
> If I want to add a user I do the following in *Java */ *Scala *code:
>
> val json = " 
> {\"_id\":\"1\",\"name\":\"Anthony\",\"birthDate\":\"2013-04-10T06:45:26.186Z\"}"
> val updateRequest = new UpdateRequest("indexName", "customer", customerId)
> updateRequest.script(" if (ctx._source.users == null) { ctx._source.users 
> =  "+json+"  } else {  ctx._source.users += "+json+" } ")
>
> This works OK for adding nested *users *AKA updating the *customer root 
> type* document.
>
> How is it to be done for *deleting* or *updating *a specific user ID from 
> the nested *users* nested document?
>
>
> 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 elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/171950f9-5843-4327-be49-b6858e1b3832%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to