Re: delete/update nested documents with elasticsearch Java API

2014-10-27 Thread Rajit Garg
Thanks this is working

On Tuesday, October 28, 2014 8:40:12 AM UTC+5:30, shar...@gmail.com wrote:
>
>
> "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/a4ccc10c-a06e-4c47-b486-8fdd1da4bfa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: delete/update nested documents with elasticsearch Java API

2014-10-27 Thread sharp00k

"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.


Re: delete/update nested documents with elasticsearch Java API

2014-10-08 Thread 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/171950f9-5843-4327-be49-b6858e1b3832%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: delete/update nested documents with elasticsearch Java API

2014-10-07 Thread Rajit Garg
Hi,

I have tried to update or remove the nested object in the same way as 
suggested , but this is not working

I am doing this

client.update({"index": "daffosw","type": "daffo","id": "2501","body": {
"script" : "for (int i = 0; i < ctx._source.users.size(); i++){
if(ctx._source.users[i]_id == id){
ctx._source.users[i].name = 'Updated John';
}
}",
"params" : {
  "id" : "1"
}
}}


my users field contain the following

 "users": [
{
  "code": "abcd",
  "_id": "1",
  "name": "naveen"
},
{
  "code": "efgh",
  "_id": "2",
  "name": "rajit"
},
{
  "code": "ijkl",
  "_id": "3",
  "name": "ashu"
}
  ]


and I am getting this error


VerifyError[Bad type on operand stack
Exception Details:
  Location:

ASMAccessorImpl_11232799721412745799160.setValue(Ljava/lang/Object;Ljava/lang/Object;Lorg/elasticsearch/common/mvel2/integration/VariableResolverFactory;Ljava/lang/Object;)Ljava/lang/Object;
 @49: invokeinterface
  Reason:
Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 
integer
  Current Frame:
bci: @49
flags: { }
locals: { 'ASMAccessorImpl_11232799721412745799160', 'java/lang/Object', 
'java/lang/Object', 
'org/elasticsearch/common/mvel2/integration/VariableResolverFactory', 
'java/lang/Object' }
stack: { 'java/util/List', 'java/lang/Object' }
  Bytecode:
000: 2d12 0eb9 0014 0200 b900 1a01 00c0 001c
010: 121e b900 2202 00c0 001c 1224 b900 2202
020: 00c0 0026 2d12 28b9 0014 0200 b900 1a01
030: 00b9 002b 0200 c000 2d12 2f19 04b6 0035
040: 1904 b0
]
Error: VerifyError[Bad type on operand stack
Exception Details:
  Location:

-

-





On Friday, April 12, 2013 1:16:33 AM UTC+5:30, Martijn v Groningen wrote:
>
> Hi Andrei,
>
> I think the following should work:
> "script" : "for (int i = 0; i < ctx._source.users.size(); 
> i++){if(ctx._source.users[i]._id == id){ctx._source.users.remove(i);i--;}}"
>
> I added: 'i--'. Once an entry is removed, the list has been shorter and we 
> shouldn't skip over the next entry.
>
> Martijn 
>
>
> On 11 April 2013 18:04, Andrei Tolnai > 
> wrote:
>
>> Oddly enough the DELETE script seems to be working if in the array there 
>> is only one user with a particular given *id*. :-)
>>
>> If I have multiple users with the same *_id* value the script is not 
>> removing all of them. How should the script be changed to remove all the 
>> users that have a specific *_id* value?
>>
>> Regards.
>>
>
>
>
> -- 
> Met vriendelijke groet,
>
> Martijn van Groningen 
>

-- 
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/5671672d-cc4e-451b-93a6-e40b574ea467%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.