Re: help needed scripting update to list element (bulk request)

2014-08-31 Thread eunever32
Thanks David

On Sunday, August 31, 2014 7:48:38 PM UTC+1, David Pilato wrote:
>
> You can't do it with elasticsearch but you could try this plugin: 
> https://github.com/yakaz/elasticsearch-action-updatebyquery
>
> HTH
>
> --
> David ;-)
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
>
>
> Le 31 août 2014 à 20:22, eune...@gmail.com  a écrit :
>
> Hey 
>
> I figured it out, but it leads me on to another question.
>
> So the way to execute a script over a list of elements is as follows:
>
> 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"
>   }
> }
>
> My next question: how can I query the index to find all matching documents 
> with say "tweet_id": "123" and then execute the script on only those 
> documents?
>
> When I tried 
> .. query..
> {
>"filter": {
>  "script": "foreach (item : ctx._source.list) {if (item['tweet_id'] == 
> tweet_id) { item['new_field'] = 'ghi'; }  }",
>   "params": {
> "tweet_id": "123"
>   }
> }
> }
> I got an error saying property : ctx : unresolvable
>
> Thanks.
>
> On Friday, August 29, 2014 10:33:23 AM UTC+1, eune...@gmail.com wrote:
>>
>> Hi
>> Say I have a list of elements like this:
>>
>> PUT twitter/twit/1
>> {
>>"list": [
>>{
>>   "a": "b",
>>   "c": "d",
>> *  "e": "f"*
>> },
>> {
>>   "1": "2",
>>   "3": "4"
>> }
>> ]
>> }
>>
>> And I want to change the value of "e" (currently "f") to say "new_f " 
>> such that the document looks like: 
>>
>> {
>>"list": [
>>{
>>   "a": "b",
>>   "c": "d",
>> *  "e": "new_f"*
>> },
>> {
>>   "1": "2",
>>   "3": "4"
>> }
>> ]
>> }
>>
>> Is there a way to do this ? Maybe in MVEL ?
>>
>> Do I match on document 
>>{
>>   "a": "b",
>>   "c": "d",
>>   "e": "f"
>> }
>>
>> ie if list.contains(document) { some kind of update; }  // is this 
>> possible ?
>>
>>
>> I know MVEL is being deprecated in 1.4 however it will do for now. 
>>
>> I want to use bulk request. 
>>
>> I know it's possible to remove the element like this: 
>> bulkRequestBuilder.setScript("if (ctx._source.list.contains(document)) 
>> {ctx._source.list.remove(document)} }").setScriptParams etc
>>
>>
>> but is it possible to "update" a field in the document also ?
>>
>> 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 elasticsearc...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elasticsearch/5c641a4e-a02f-4ebe-972f-cd2a320d15d4%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/03702904-fd4a-4fed-8bb7-4204dccebfd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: help needed scripting update to list element (bulk request)

2014-08-31 Thread David Pilato
You can't do it with elasticsearch but you could try this plugin: 
https://github.com/yakaz/elasticsearch-action-updatebyquery

HTH

--
David ;-)
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs


Le 31 août 2014 à 20:22, euneve...@gmail.com a écrit :

Hey 

I figured it out, but it leads me on to another question.

So the way to execute a script over a list of elements is as follows:

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

My next question: how can I query the index to find all matching documents with 
say "tweet_id": "123" and then execute the script on only those documents?

When I tried 
.. query..
{
   "filter": {
 "script": "foreach (item : ctx._source.list) {if (item['tweet_id'] == 
tweet_id) { item['new_field'] = 'ghi'; }  }",
  "params": {
"tweet_id": "123"
  }
}
}
I got an error saying property : ctx : unresolvable

Thanks.

> On Friday, August 29, 2014 10:33:23 AM UTC+1, eune...@gmail.com wrote:
> Hi
> Say I have a list of elements like this:
> 
> PUT twitter/twit/1
> {
>"list": [
>{
>   "a": "b",
>   "c": "d",
>   "e": "f"
> },
> {
>   "1": "2",
>   "3": "4"
> }
> ]
> }
> 
> And I want to change the value of "e" (currently "f") to say "new_f " such 
> that the document looks like:
> 
> {
>"list": [
>{
>   "a": "b",
>   "c": "d",
>   "e": "new_f"
> },
> {
>   "1": "2",
>   "3": "4"
> }
> ]
> }
> 
> Is there a way to do this ? Maybe in MVEL ?
> 
> Do I match on document
>{
>   "a": "b",
>   "c": "d",
>   "e": "f"
> }
> 
> ie if list.contains(document) { some kind of update; }  // is this possible ?
> 
> 
> I know MVEL is being deprecated in 1.4 however it will do for now.
> 
> I want to use bulk request.
> 
> I know it's possible to remove the element like this:
> bulkRequestBuilder.setScript("if (ctx._source.list.contains(document)) 
> {ctx._source.list.remove(document)} }").setScriptParams etc
> 
> 
> but is it possible to "update" a field in the document also ?
> 
> 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/5c641a4e-a02f-4ebe-972f-cd2a320d15d4%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/234C2E37-8860-4015-84A3-6326C27DA17F%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.


Re: help needed scripting update to list element (bulk request)

2014-08-31 Thread eunever32
Hey 

I figured it out, but it leads me on to another question.

So the way to execute a script over a list of elements is as follows:

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

My next question: how can I query the index to find all matching documents 
with say "tweet_id": "123" and then execute the script on only those 
documents?

When I tried 
.. query..
{
   "filter": {
 "script": "foreach (item : ctx._source.list) {if (item['tweet_id'] == 
tweet_id) { item['new_field'] = 'ghi'; }  }",
  "params": {
"tweet_id": "123"
  }
}
}
I got an error saying property : ctx : unresolvable

Thanks.

On Friday, August 29, 2014 10:33:23 AM UTC+1, eune...@gmail.com wrote:
>
> Hi
> Say I have a list of elements like this:
>
> PUT twitter/twit/1
> {
>"list": [
>{
>   "a": "b",
>   "c": "d",
> *  "e": "f"*
> },
> {
>   "1": "2",
>   "3": "4"
> }
> ]
> }
>
> And I want to change the value of "e" (currently "f") to say "new_f " such 
> that the document looks like: 
>
> {
>"list": [
>{
>   "a": "b",
>   "c": "d",
> *  "e": "new_f"*
> },
> {
>   "1": "2",
>   "3": "4"
> }
> ]
> }
>
> Is there a way to do this ? Maybe in MVEL ?
>
> Do I match on document 
>{
>   "a": "b",
>   "c": "d",
>   "e": "f"
> }
>
> ie if list.contains(document) { some kind of update; }  // is this 
> possible ?
>
>
> I know MVEL is being deprecated in 1.4 however it will do for now. 
>
> I want to use bulk request. 
>
> I know it's possible to remove the element like this: 
> bulkRequestBuilder.setScript("if (ctx._source.list.contains(document)) 
> {ctx._source.list.remove(document)} }").setScriptParams etc
>
>
> but is it possible to "update" a field in the document also ?
>
> 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/5c641a4e-a02f-4ebe-972f-cd2a320d15d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: help needed scripting update to list element (bulk request)

2014-08-31 Thread eunever32
Any takers?
David Pilato?


On Friday, August 29, 2014 10:33:23 AM UTC+1, eune...@gmail.com wrote:
>
> Hi
> Say I have a list of elements like this:
>
> PUT twitter/twit/1
> {
>"list": [
>{
>   "a": "b",
>   "c": "d",
> *  "e": "f"*
> },
> {
>   "1": "2",
>   "3": "4"
> }
> ]
> }
>
> And I want to change the value of "e" (currently "f") to say "new_f " such 
> that the document looks like: 
>
> {
>"list": [
>{
>   "a": "b",
>   "c": "d",
> *  "e": "new_f"*
> },
> {
>   "1": "2",
>   "3": "4"
> }
> ]
> }
>
> Is there a way to do this ? Maybe in MVEL ?
>
> Do I match on document 
>{
>   "a": "b",
>   "c": "d",
>   "e": "f"
> }
>
> ie if list.contains(document) { some kind of update; }  // is this 
> possible ?
>
>
> I know MVEL is being deprecated in 1.4 however it will do for now. 
>
> I want to use bulk request. 
>
> I know it's possible to remove the element like this: 
> bulkRequestBuilder.setScript("if (ctx._source.list.contains(document)) 
> {ctx._source.list.remove(document)} }").setScriptParams etc
>
>
> but is it possible to "update" a field in the document also ?
>
> 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/571fa34d-f7fa-4f17-81c2-1288a0357d68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


help needed scripting update to list element (bulk request)

2014-08-29 Thread eunever32
Hi
Say I have a list of elements like this:

PUT twitter/twit/1
{
   "list": [
   {
  "a": "b",
  "c": "d",
*  "e": "f"*
},
{
  "1": "2",
  "3": "4"
}
]
}

And I want to change the value of "e" (currently "f") to say "new_f " such 
that the document looks like: 

{
   "list": [
   {
  "a": "b",
  "c": "d",
*  "e": "new_f"*
},
{
  "1": "2",
  "3": "4"
}
]
}

Is there a way to do this ? Maybe in MVEL ?

Do I match on document 
   {
  "a": "b",
  "c": "d",
  "e": "f"
}

ie if list.contains(document) { some kind of update; }  // is this possible 
?


I know MVEL is being deprecated in 1.4 however it will do for now. 

I want to use bulk request. 

I know it's possible to remove the element like this: 
bulkRequestBuilder.setScript("if (ctx._source.list.contains(document)) 
{ctx._source.list.remove(document)} }").setScriptParams etc


but is it possible to "update" a field in the document also ?

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/da238495-7cf3-4215-a77e-2144499b8859%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.