"script": "removeObjects = new java.util.ArrayList(); foreach (item : 
ctx._source.list) {if (item['tweet_id'] == tweet_id) 
{removeObjects.add(item) } } 
for(removeObject:removeObjects){ctx._source.list.remove(removeObject);}",

2014년 10월 8일 수요일 오후 8시 12분 55초 UTC+9, Rajit Garg 님의 말:
>
> 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/8ef09dca-306d-4fa7-8936-a20e86125dac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to