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:
    0000000: 2d12 0eb9 0014 0200 b900 1a01 00c0 001c
    0000010: 121e b900 2202 00c0 001c 1224 b900 2202
    0000020: 00c0 0026 2d12 28b9 0014 0200 b900 1a01
    0000030: 00b9 002b 0200 c000 2d12 2f19 04b6 0035
    0000040: 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 <dre...@gmail.com <javascript:>> 
> 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.

Reply via email to