*I have seen the nested docs, and create mapping and getting mapping as
follow:- *
"fields": {
"type": "nested",
"properties": {
"_id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
where fields is my array containing
"fields": [
{
"_id": "1",
"name": "naveen"
},
{
"_id": "2",
"name": "rajit"
},
{
"_id": "3",
"name": "ashu"
}
]
Now I want to update and remove object from this array, and I am doing
this as follow:-
client.update({"index": "daffosw","type": "daffo","id": "2501","body": {
"script" : "for (int i = 0; i < ctx._source.fields.size(); i++){
if(ctx._source.fields[i]_id == id){
ctx._source.fields.remove(i);
}
}",
"params" : {
"id" : "1"
}
}}
but this will give this error
VerifyError[Bad type on operand stack
Exception Details:
Location:
ASMAccessorImpl_19994590841412749253560.getValue(Ljava/lang/Object;Ljava/lang/Object;Lorg/elasticsearch/common/mvel2/integration/VariableResolverFactory;)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_19994590841412749253560', 'java/lang/Object', 'java/lang/Object', 'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
stack: { 'java/util/List', 'java/lang/Object' }
Bytecode:
0000000: 2d12 0eb9 0014 0200 b900 1901 00c0 001b
0000010: 121d b900 2102 00c0 001b 1223 b900 2102
0000020: 00c0 0025 2d12 27b9 0014 0200 b900 1901
0000030: 00b9 002a 0200 c000 1b12 2cb9 0021 0200
0000040: b0
]
Error: VerifyError[Bad type on operand stack..................
..............................
..................................
...................................
.....................................
................................
*then I am doing this *
client.update({"index": "daffosw","type": "daffo","id": "2501","body": {
"script" : "for (element : ctx._source['fields'].size()){
if(element._id == id){
element.name = 'Updated John';
}
}",
"params" : {
"id" : "1"
}
}}
and this is giving this error
ElasticsearchIllegalArgumentException[failed to execute script]; nested: PropertyAccessException[[Error: could not access: _id; in class: java.lang.Integer]
then I am doing this
client.update({"index": "daffosw","type": "daffo","id": "2501","body": {
"script" : "for (element : doc['fields'].values){ if(element._id == id){
element.name = 'Updated John'; } }", "params" : { "id" : "1" } }}
and this is giving this error
ElasticsearchIllegalArgumentException[failed to execute script]; nested: PropertyAccessException[[Error: unresolvable property or identifier: doc]
please help
On Tuesday, October 7, 2014 7:17:02 PM UTC+5:30, David Pilato wrote:
Use nested documents.
See
Elasticsearch Platform — Find real-time answers at scale | Elastic
Elasticsearch Platform — Find real-time answers at scale | Elastic
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html#mapping-nested-type
--
David Pilato | Technical Advocate | elasticsearch.com
http://elasticsearch.com
david....@elasticsearch.com <javascript:>
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
http://twitter.com/scrutmydocs
https://twitter.com/scrutmydocs
Le 7 octobre 2014 à 15:38:56, Rajit Garg (rajit...@daffodilsw.com
<javascript:>) a écrit:
Here I have a array type field in my document of Elasticsearch, like
below:-
"prog_lists": [
{
"description": "engineer",
"age": 25,
"name": "ashu"
},
{
"description": "programmer",
"age": 26,
"name": "rajit"
},
{
"description": "designer",
"age": 27,
"name": "naveen"
}
]
I want to update only those objects which satisfy any condition, like I want to query where name equals to ashu update his age to 30.
please suggest something....
Thanks in advance....
--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/1ed154d1-a441-46c9-bc37-82cc360ef7aa%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/1ed154d1-a441-46c9-bc37-82cc360ef7aa%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/894db422-23e9-44b2-9432-585bda23c73c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.