Re: elastic search date range aggregation not giving complete data

2014-11-05 Thread Rajit Garg
*Hi kazoompa,*

*Suppose I have below Data in index=cars and type=transactions*
[
  {
"price": 2,
"color": "red",
"make": "honda",
"sold": "2014-11-05"
  },
  {
"price": 12000,
"color": "green",
"make": "toyota",
"sold": "2014-08-19"
  },
  {
"price": 8,
"color": "red",
"make": "bmw",
"sold": "2014-01-01"
  },
  {
"price": 2,
"color": "red",
"make": "honda",
"sold": "2014-11-05"
  },
  {
"price": 3,
"color": "green",
"make": "ford",
"sold": "2014-05-18"
  },
  {
"price": 15000,
"color": "blue",
"make": "toyota",
"sold": "2014-07-02"
  },
  {
"price": 1,
"color": "red",
"make": "honda",
"sold": "2014-10-28"
  },
  {
"price": 25000,
"color": "blue",
"make": "ford",
"sold": "2014-02-12"
  },
  {
"price": "5",
"color": "yellow",
"make": "Maruti",
"sold": "2014-10-11"
  }
]

Now I am Querying for getting aggregate data based on date_range, like 
below**


"aggs": {
"range": {
"date_range": {
"field": "sold",
"ranges": [
{  "from": "2014-11-01", "to": "2014-11-30" }
]
}
}
}
 i.e. date range from 1st nov to 30th nov , for this I am getting this 
output

 
 "aggregations": {
"range": {
  "buckets": [
{
  "key": "2014-11-01T00:00:00.000Z-2014-11-30T00:00:00.000Z",
  "from": 14148,
  "from_as_string": "2014-11-01T00:00:00.000Z",
  "to": 141730560,
  "to_as_string": "2014-11-30T00:00:00.000Z",
  "doc_count": 2
}
  ]
}
  }

from output I am getting that I have two data(doc_count) which come under 
this range,ok

But if i have required those data which satisfies this condition or range 
like below

  {
"price": 2,
"color": "red",
"make": "honda",
"sold": "2014-11-05"
  }

 {
"price": 2,
"color": "red",
"make": "honda",
"sold": "2014-11-05"
  }

What I have required to do for thisplease help???

On Thursday, November 6, 2014 8:27:05 AM UTC+5:30, kazoompa wrote:
>
> What do you mean by " I have also required complete aggregate data", you 
> result is based on the type of the aggregation you use.
>
> may be you can elaborate more.
>
> Ramin
>
> On Monday, November 3, 2014 11:33:55 PM UTC-5, Rajit Garg wrote:
>>
>> **I am Querying for getting aggregate data based on date_range, like 
>> below**
>>
>> "aggs": {
>> "range": {
>> "date_range": {
>> "field": "sold",
>> "ranges": [
>> {  "from": "2014-11-01", "to": "2014-11-30" },
>> {  "from": "2014-08-01", "to": "2014-08-31" } 
>> ]
>> }
>> }
>> }
>>
>>
>> **using this I am getting this response**
>>
>>
>>  
>>
>> "aggregations": {
>> "range": {
>>   "buckets": [
>> {
>>   "key": "2014-08-01T00:00:00.000Z-2014-08-31T00:00:00.000Z",
>>   "from": 140685120,
>>   "from_as_string": "2014-08-01T00:00:00.000Z",
>>   "to": 140944320,
>>   "to_as_string": "2014-08-31T00:00:00.000Z",
>>   "doc_count": 1
>> },
>> {
>>   "key": "2014-11-01T00:00:00.000Z-2014-11-30T00:00:00.000Z",
>>   "from": 14148,
>>   "from_as_string": "2014-11-01T00:00:00.000Z",
>>   "to": 141730560,
>>   "to_as_string": "2014-11-30T00:00:00.000Z",
>>   "doc_count": 2
>> }
>>   ]
>> }
>>   }
>>
>> **but instead of only doc_count, I have also required complete aggregate 
>> data that satisfy this range,
>> is threre any way to get this..please help**
>>
>

-- 
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/8a51d4f1-c848-41eb-a221-ed546ab14129%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


elastic search date range aggregation not giving complete data

2014-11-03 Thread Rajit Garg
**I am Querying for getting aggregate data based on date_range, like below**

"aggs": {
"range": {
"date_range": {
"field": "sold",
"ranges": [
{  "from": "2014-11-01", "to": "2014-11-30" },
{  "from": "2014-08-01", "to": "2014-08-31" } 
]
}
}
}


**using this I am getting this response**


 

"aggregations": {
"range": {
  "buckets": [
{
  "key": "2014-08-01T00:00:00.000Z-2014-08-31T00:00:00.000Z",
  "from": 140685120,
  "from_as_string": "2014-08-01T00:00:00.000Z",
  "to": 140944320,
  "to_as_string": "2014-08-31T00:00:00.000Z",
  "doc_count": 1
},
{
  "key": "2014-11-01T00:00:00.000Z-2014-11-30T00:00:00.000Z",
  "from": 14148,
  "from_as_string": "2014-11-01T00:00:00.000Z",
  "to": 141730560,
  "to_as_string": "2014-11-30T00:00:00.000Z",
  "doc_count": 2
}
  ]
}
  }

**but instead of only doc_count, I have also required complete aggregate 
data that satisfy this range,
is threre any way to get this..please help**

-- 
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/64ae05fa-2623-4a9d-b590-be02529d6a52%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 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: how to update a object within array in elastic search

2014-10-10 Thread Rajit Garg
**I have got my answer, and its solution is** 

POST /twitter/twit/1/_update

{
  "script": "item_to_remove = nil; foreach (item : ctx._source.list) { 
if (item['tweet_id'] == tweet_id) { item_to_remove=item; } } if 
(item_to_remove != nil) ctx._source.list.remove(item_to_remove);",
  "params": {"tweet_id": "123"}
}


**if you have more than one item that matches the criteria, use a list 
instead:**


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

On Tuesday, June 24, 2014 12:48:17 PM UTC+5:30, Madhumita Sadhukhan wrote:
>
> I have a requirement where I need to update(not append) existing values 
> within a list or array in Elastic Search.
> Is this feature supported in elastic search?
>
> For eg:
>
> I have a field called jobs as part of my document
>
> "jobs": [
>   {
>  "status": "InProgress",
>  "runId": 1,
>  "start_date": 2101112,
>  "orderId": "undefined"
>   },
>   {
>  "status": "InProgress",
>  "runId": 2,
>  "start_date": 2101112,
>  "orderId": "undefined"
>   },
>    ],
> and I am required to update the orderId for each job run to different 
> values.
> Currently I am only able to append a job but I cannot update the 
> attributes of each job later.
> Is this usecase supported and possible in Elastic Search?
>

On Wednesday, October 8, 2014 4:44:45 PM UTC+5:30, Rajit Garg wrote:
>
> *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, October 8, 2014 12:42:11 PM UTC+5:30, Rajit Garg wrote:
>>
>> I have read the nested docs and create mapping and get mapping as follow
>>
>> "fields": {
>> "type": "nested",
>> "properties": {
>>   "_id": {
>> "type": "string"
>>   },
>>   "name": {
>> "type": "string"
>>   }
>> }
>>   }
>>
>>
>> where fields is my array contain the following
>>
>> "fields": [
>> {
>>   "_id": "1",
>>   "name": "naveen"
>> },
>> {
>>   "_id": "2",
>>   "name": "rajit"
>> },
>> {
>>   "_id": "3",
>>   "name": &quo

Re: Update existing values within a list or array in Elastic Search

2014-10-10 Thread Rajit Garg
**I have got my answer, and its solution is** 

POST /twitter/twit/1/_update

{
  "script": "item_to_remove = nil; foreach (item : ctx._source.list) { 
if (item['tweet_id'] == tweet_id) { item_to_remove=item; } } if 
(item_to_remove != nil) ctx._source.list.remove(item_to_remove);",
  "params": {"tweet_id": "123"}
}


**if you have more than one item that matches the criteria, use a list 
instead:**


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

On Tuesday, June 24, 2014 12:48:17 PM UTC+5:30, Madhumita Sadhukhan wrote:
>
> I have a requirement where I need to update(not append) existing values 
> within a list or array in Elastic Search.
> Is this feature supported in elastic search?
>
> For eg:
>
> I have a field called jobs as part of my document
>
> "jobs": [
>   {
>  "status": "InProgress",
>  "runId": 1,
>  "start_date": 2101112,
>  "orderId": "undefined"
>   },
>   {
>  "status": "InProgress",
>  "runId": 2,
>  "start_date": 2101112,
>  "orderId": "undefined"
>   },
>    ],
> and I am required to update the orderId for each job run to different 
> values.
> Currently I am only able to append a job but I cannot update the 
> attributes of each job later.
> Is this usecase supported and possible in Elastic Search?
>

On Wednesday, October 8, 2014 4:41:45 PM UTC+5:30, Rajit Garg wrote:
>
> 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 Tuesday, October 7, 2014 6:38:38 PM UTC+5:30, Rajit Garg wrote:
>>
>> I also have the same question, I have a array type field in my document 
>> of elastic search, 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 one object from this array i.e. i want to query 
>> where name equals to ashu then update his age to 30. How I can achieve 
>> this in elastic search
>>
>> please suggest something...
>>
>>
>> On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:
>>>
>>> Just send the full new version of your document and you're done.
>>> Elasticsearch will index the new content.
>>>
>>> If I 

Re: update or remove object from array not working in elastic search

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, October 8, 2014 12:48:50 PM UTC+5:30, Rajit Garg wrote:
>
> *I have read the nested docs and create mapping and get mapping as follow*
>
> "fields": {
> "type": "nested",
> "properties": {
>   "_id": {
> "type": "string"
>   },
>   "name": {
> "type": "string"
>   }
> }
>   }
>
>
> *where fields is my array contain the following*
>
> "fields": [
> {
>   "_id": "1",
>   "name": "naveen"
> },
> {
>   "_id": "2",
>   "name": "rajit"
> },
> {
>   "_id": "3",
>   "name": "ashu"
> }
>   ]
>
>
> *I want to update and remove object from this array, and I am doing this,*
>
> 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[i].name = 'Updated John';
> }
> }",
> "params" : {
>   "id" : "1"
> }
> }}
>
> *and I am getting this error*
>
> VerifyError[Bad type on operand stack
> Exception Details:
>   Location:
> 
> ASMAccessorImpl_18539991071412750271920.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_18539991071412750271920', 
> 'java/lang/Object', 'java/lang/Object', 
> 'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
> stack: { 'java/util/List', 'java/lang/Object' }
> .
> .
>
>
>
> *then I have tried this*
>
> 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"
> }
> }}
>
>
> *and this is giving the same type of error*
>
>
> *then I have tried*
>
>
> 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"
> }
> }}
>
>
> *which gives this error*
>
> *elasticsearchIllegalArgumentException[failed to execute script]; nested: 
> PropertyAccessException[[Error: unresolvable property or identifier: doc]*
>
>
> please help
>

-- 
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/6c3b31f6-2611-4e32-9a8d-a03b01854685%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to update a object within array in elastic search

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, October 8, 2014 12:42:11 PM UTC+5:30, Rajit Garg wrote:
>
> I have read the nested docs and create mapping and get mapping as follow
>
> "fields": {
> "type": "nested",
> "properties": {
>   "_id": {
> "type": "string"
>   },
>   "name": {
> "type": "string"
>   }
> }
>   }
>
>
> where fields is my array contain the following
>
> "fields": [
> {
>   "_id": "1",
>   "name": "naveen"
> },
> {
>   "_id": "2",
>   "name": "rajit"
> },
> {
>   "_id": "3",
>   "name": "ashu"
> }
>   ]
>
>
> I want to update and remove object from this array, and I am doing this,
>
> 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[i].name = 'Updated John';
> }
> }",
> "params" : {
>   "id" : "1"
> }
> }}
>
> and I am getting this error
>
> VerifyError[Bad type on operand stack
> Exception Details:
>   Location:
> 
> ASMAccessorImpl_18539991071412750271920.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_18539991071412750271920', 
> 'java/lang/Object', 'java/lang/Object', 
> 'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
> stack: { 'java/util/List', 'java/lang/Object' }
> .
> .
>
>
>
> then I have tried this
>
> 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"
> }
> }}
>
>
> and this is giving the same type of error
>
>
> then I have tried
>
>
> 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"
> }
> }}
>
>
> which gives this error
>
> elasticsearchIllegalArgu

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: Update existing values within a list or array in Elastic Search

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 Tuesday, October 7, 2014 6:38:38 PM UTC+5:30, Rajit Garg wrote:
>
> I also have the same question, I have a array type field in my document 
> of elastic search, 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 one object from this array i.e. i want to query 
> where name equals to ashu then update his age to 30. How I can achieve 
> this in elastic search
>
> please suggest something...
>
>
> On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:
>>
>> Just send the full new version of your document and you're done.
>> Elasticsearch will index the new content.
>>
>> If I did not answer to you question, may be you should provide an example 
>> as a Gist so we can comment with more details???
>>
>>
>>
>> -- 
>> *David Pilato* | *Technical Advocate* | *Elasticsearch.com*
>> @dadoonet <https://twitter.com/dadoonet> | @elasticsearchfr 
>> <https://twitter.com/elasticsearchfr>
>>
>>
>> Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan (madhumita...@gmail.com) 
>> a écrit:
>>
>>
>> I am not removing any element from an array I need to update particular 
>> existing elements within an array.
>> Currently I ma using the Update API in Elastic Search to append new 
>> elements within the array but it fails when I try to update values of 
>> existing elements.
>>
>> For eg:
>>
>> I am able to add a new record as follows to jobs list using Update API 
>> scripts
>>
>> {
>>  "status": "InProgress",
>>  "runId": 2,
>>  "start_date": 2101112,
>>  "orderId": "undefined"
>>   },
>>
>>
>> What I need is how to update orderId value from 'undefined' to say 'abcd' 
>> using update api.
>> Is this supported?
>> Is Elastic Search supporting indexing in arrays or lists?
>>
>> On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote: 
>>>
>>>  If you send the full document without the element you need to remove 
>>> in the array, this should work fine.
>>>  How do you actually update your document?
>>>  
>>>   -- 
>>> *David Pilato* | *Technical Advocate* | *Elasticsearch.com* 
>>>  @dadoonet <https://twitter.com/dadoonet> | @elasticsearchfr 
>>> <https://twitter.com/elasticsearchfr>
>>>  
>>>
>>> Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita...@gmail.com) 
>>> a écrit:
>>>
>>>  I have a requirement where I need to update(not append) existing 
>>> values within a list or array in Elastic Search.
>>> Is this feature supported in elastic search?
>>>
>>> For eg:
>>>
>>> I have a field called jobs as part of my document
>>>
>>> "jobs": [
>>> 

Re: how to update a object within array in elastic search

2014-10-08 Thread Rajit Garg
*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:
000: 2d12 0eb9 0014 0200 b900 1901 00c0 001b
010: 121d b900 2102 00c0 001b 1223 b900 2102
020: 00c0 0025 2d12 27b9 0014 0200 b900 1901
030: 00b9 002a 0200 c000 1b12 2cb9 0021 0200
040: 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 
>
> http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-objects.html#nested-objects
>
> http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html#mapping-nested-type
>
>
> <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 
> @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 
> ) a écrit:
>
>  Here I have a array type field in my document of ela

Re: how to update a object within array in elastic search

2014-10-08 Thread Rajit Garg
I have read the nested docs and create mapping and get mapping as follow

"fields": {
"type": "nested",
"properties": {
  "_id": {
"type": "string"
  },
  "name": {
"type": "string"
  }
}
  }


where fields is my array contain the following

"fields": [
{
  "_id": "1",
  "name": "naveen"
},
{
  "_id": "2",
  "name": "rajit"
},
{
  "_id": "3",
  "name": "ashu"
}
  ]


I want to update and remove object from this array, and I am doing this,

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[i].name = 'Updated John';
}
}",
"params" : {
  "id" : "1"
}
}}

and I am getting this error

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

ASMAccessorImpl_18539991071412750271920.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_18539991071412750271920', 
'java/lang/Object', 'java/lang/Object', 
'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
stack: { 'java/util/List', 'java/lang/Object' }
.
.



then I have tried this

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


and this is giving the same type of error


then I have tried


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


which gives this error

elasticsearchIllegalArgumentException[failed to execute script]; nested: 
PropertyAccessException[[Error: unresolvable property or identifier: doc]


please help

On Tuesday, October 7, 2014 7:08:52 PM UTC+5:30, Rajit Garg wrote:
>
> Here I have a array type field in my document of elastic search, 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 elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/cc5e8892-9083-492e-834f-ac3be92abb06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


update or remove object from array not working in elastic search

2014-10-08 Thread Rajit Garg
*I have read the nested docs and create mapping and get mapping as follow*

"fields": {
"type": "nested",
"properties": {
  "_id": {
"type": "string"
  },
  "name": {
"type": "string"
  }
}
  }


*where fields is my array contain the following*

"fields": [
{
  "_id": "1",
  "name": "naveen"
},
{
  "_id": "2",
  "name": "rajit"
},
{
  "_id": "3",
  "name": "ashu"
}
  ]


*I want to update and remove object from this array, and I am doing this,*

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[i].name = 'Updated John';
}
}",
"params" : {
  "id" : "1"
}
}}

*and I am getting this error*

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

ASMAccessorImpl_18539991071412750271920.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_18539991071412750271920', 
'java/lang/Object', 'java/lang/Object', 
'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
stack: { 'java/util/List', 'java/lang/Object' }
.
.



*then I have tried this*

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


*and this is giving the same type of error*


*then I have tried*


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


*which gives this error*

*elasticsearchIllegalArgumentException[failed to execute script]; nested: 
PropertyAccessException[[Error: unresolvable property or identifier: doc]*


please help

-- 
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/1c65f529-6e6b-4415-8f93-662acbac9929%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to update a object within array in elastic search

2014-10-08 Thread Rajit Garg
*I have read the nested docs and create mapping and get mapping as follow*

"fields": {
"type": "nested",
"properties": {
  "_id": {
"type": "string"
  },
  "name": {
"type": "string"
  }
}
  }


*where fields is my array contain the following*

"fields": [
{
  "_id": "1",
  "name": "naveen"
},
{
  "_id": "2",
  "name": "rajit"
},
{
  "_id": "3",
  "name": "ashu"
}
  ]


*I want to update and remove object from this array, and I am doing this,*

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[i].name = 'Updated John';
}
}",
"params" : {
  "id" : "1"
}
}}

*and I am getting this error*

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

ASMAccessorImpl_18539991071412750271920.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_18539991071412750271920', 
'java/lang/Object', 'java/lang/Object', 
'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
stack: { 'java/util/List', 'java/lang/Object' }
.
.



*then I have tried this*

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


*and this is giving the same type of error*


*then I have tried*


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


*which gives 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 
>
> http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-objects.html#nested-objects
>
> http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html#mapping-nested-type
>
>
> <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 
> @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 
> ) a écrit:
>
>  Here I have a array type field in my document of elastic search, 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 equal

Re: how to update a object within array in elastic search

2014-10-08 Thread Rajit Garg
I have read the nested docs and create mapping and get mapping as follow

"fields": {
"type": "nested",
"properties": {
  "_id": {
"type": "string"
  },
  "name": {
"type": "string"
  }
}
  }


where fields is my array contain the following

"fields": [
{
  "_id": "1",
  "name": "naveen"
},
{
  "_id": "2",
  "name": "rajit"
},
{
  "_id": "3",
  "name": "ashu"
}
  ]


I want to update and remove object from this array, and I am doing this,

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[i].name = 'Updated John';
}
}",
"params" : {
  "id" : "1"
}
}}

and I am getting this error

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

ASMAccessorImpl_18539991071412750271920.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_18539991071412750271920', 
'java/lang/Object', 'java/lang/Object', 
'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
stack: { 'java/util/List', 'java/lang/Object' }
.
.



then I have tried this

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


and this is giving the same type of error


then I have tried


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


which gives this error

elasticsearchIllegalArgumentException[failed to execute script]; nested: 
PropertyAccessException[[Error: unresolvable property or identifier: doc]


please help

On Tuesday, October 7, 2014 7:08:52 PM UTC+5:30, Rajit Garg wrote:
>
> Here I have a array type field in my document of elastic search, 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 elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/ef9566bb-eebc-43e4-9a97-b8f832cf7e7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to update a object within array in elastic search

2014-10-08 Thread Rajit Garg
I have read the nested docs and create mapping and get mapping as follow

"fields": {
"type": "nested",
"properties": {
  "_id": {
"type": "string"
  },
  "name": {
"type": "string"
  }
}
  }


where fields is my array contain the following

"fields": [
{
  "_id": "1",
  "name": "naveen"
},
{
  "_id": "2",
  "name": "rajit"
},
{
  "_id": "3",
  "name": "ashu"
}
  ]


I want to update and remove object from this array, and I am doing this,

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[i].name = 'Updated John';
}
}",
"params" : {
  "id" : "1"
}
}}

and I am getting this error

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

ASMAccessorImpl_18539991071412750271920.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_18539991071412750271920', 'java/lang/Object', 
'java/lang/Object', 
'org/elasticsearch/common/mvel2/integration/VariableResolverFactory' }
stack: { 'java/util/List', 'java/lang/Object' }

.

.




then I have tried this


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



and this is giving the same type of error



then I have tried



127.0.0.1:5000/rest/update?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"
}
}}



which gives this error

lasticsearchIllegalArgumentException[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 
>
> http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-objects.html#nested-objects
>
> http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html#mapping-nested-type
>
>
> <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 
> @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 
> ) a écrit:
>
>  Here I have a array type field in my document of elastic search, like 
> below:-
>  
>   "prog_lists": [
> {
>   "description": "engineer",
>   "age": 25,
>   "name": "ashu"
> },
> {
>   "description": "programmer",
>   "age": 26,
>  

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.


how to update a object within array in elastic search

2014-10-07 Thread Rajit Garg
Here I have a array type field in my document of elastic search, 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 elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/1ed154d1-a441-46c9-bc37-82cc360ef7aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Update existing values within a list or array in Elastic Search

2014-10-07 Thread Rajit Garg
I also have the same question, I have a array type field in my document of 
elastic search, 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 one object from this array i.e. i want to query where 
name equals to ashu then update his age to 30. How I can achieve this in 
elastic search

please suggest something...


On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:
>
> Just send the full new version of your document and you're done.
> Elasticsearch will index the new content.
>
> If I did not answer to you question, may be you should provide an example 
> as a Gist so we can comment with more details???
>
>
>
> -- 
> *David Pilato* | *Technical Advocate* | *Elasticsearch.com*
> @dadoonet  | @elasticsearchfr 
> 
>
>
> Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan (madhumita...@gmail.com 
> ) a écrit:
>
>
> I am not removing any element from an array I need to update particular 
> existing elements within an array.
> Currently I ma using the Update API in Elastic Search to append new 
> elements within the array but it fails when I try to update values of 
> existing elements.
>
> For eg:
>
> I am able to add a new record as follows to jobs list using Update API 
> scripts
>
> {
>  "status": "InProgress",
>  "runId": 2,
>  "start_date": 2101112,
>  "orderId": "undefined"
>   },
>
>
> What I need is how to update orderId value from 'undefined' to say 'abcd' 
> using update api.
> Is this supported?
> Is Elastic Search supporting indexing in arrays or lists?
>
> On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote: 
>>
>>  If you send the full document without the element you need to remove in 
>> the array, this should work fine.
>>  How do you actually update your document?
>>  
>>   -- 
>> *David Pilato* | *Technical Advocate* | *Elasticsearch.com* 
>>  @dadoonet  | @elasticsearchfr 
>> 
>>  
>>
>> Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan (madhumita...@gmail.com) 
>> a écrit:
>>
>>  I have a requirement where I need to update(not append) existing values 
>> within a list or array in Elastic Search.
>> Is this feature supported in elastic search?
>>
>> For eg:
>>
>> I have a field called jobs as part of my document
>>
>> "jobs": [
>>   {
>>  "status": "InProgress",
>>  "runId": 1,
>>  "start_date": 2101112,
>>  "orderId": "undefined"
>>   },
>>   {
>>  "status": "InProgress",
>>  "runId": 2,
>>  "start_date": 2101112,
>>  "orderId": "undefined"
>>   },
>>],
>> and I am required to update the orderId for each job run to different 
>> values.
>> Currently I am only able to append a job but I cannot update the 
>> attributes of each job later.
>> Is this usecase supported and possible in Elastic Search?
>> --
>> 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.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com
>>  
>> 
>> .
>> 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 elasticsearc...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com
>  
> 
> .
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/4d5ea21f-dbb7-4fd0-9649-8e0131357738%40googlegroups.com.
For more options, visit https://group