# Script not executing \_update\_by\_query

**URL:** https://discuss.elastic.co/t/script-not-executing--update-by-query/23436
**Category:** Elasticsearch
**Created:** [April 28, 2015, 12:12pm UTC](https://discuss.elastic.co/t/script-not-executing--update-by-query/23436 "2015-04-28T12:12:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![redserpent7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redserpent7/32/467_2.png) [@redserpent7](https://discuss.elastic.co/u/redserpent7)
#### Post date: [April 28, 2015, 12:12pm UTC](https://discuss.elastic.co/t/script-not-executing--update-by-query/23436/1 "2015-04-28T12:12:23Z")

</div>

Hi,

I am trying to update several documents at the same time using the update  
by query plugin.

The problem seems to be with the script as the query it self returns the  
correct result with no issues. The thing is ES seems to be able to execute  
the script as there are no exceptions in the logs. Yet nothing gets updated.

So here is the document I am indexing:

curl -XPUT 'localhost:9200/users/files/1' -d '  
{  
"path" : "path/to/file"  
"size": 200  
}'

No here is my update by query request to change the path field from  
'path/to/file' to 'another/path/to/file':

curl -XPOST 'localhost:9200/users/files/\_update\_by\_query' -d '  
{  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"path": "path/to/file"  
}  
}]  
}  
},  
"script": "def str = ctx\_source.path;\ndef str2 =  
str.replaceAll("path/to/file",  
"another/path/to/file");\nctx.\_source.path = str2;"  
}'

And this is what I get:  
{  
"ok":true,  
"took":516,  
"total":75,  
"updated":0,  
"indices":[  
{  
"new\_index":{}  
}]  
}

so the query matched 75 documents but did not update any.  
Anyone knows how can I make it work.

\*\*Here is the script in pretty form:

def str = ctx\_source.path;  
def str2 = str.replaceAll("path/to/file", "another/path/to/file");  
ctx.\_source.path = str2;

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/225aa66d-53cb-4cd9-bd94-395eb169b10b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/225aa66d-53cb-4cd9-bd94-395eb169b10b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![redserpent7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redserpent7/32/467_2.png) [@redserpent7](https://discuss.elastic.co/u/redserpent7)
#### Post date: [April 28, 2015, 12:49pm UTC](https://discuss.elastic.co/t/script-not-executing--update-by-query/23436/2 "2015-04-28T12:49:55Z")

</div>

> NVM, found the culprit.

Was missing a '.':

def str = ctx\_source.path; -\> def str = ctx\*.\*\_source.path;

Weird how there was nothing in the logs about this

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a8b1a2b7-c0c4-492d-b4e4-29b90389d2a6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a8b1a2b7-c0c4-492d-b4e4-29b90389d2a6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [April 28, 2015, 12:53pm UTC](https://discuss.elastic.co/t/script-not-executing--update-by-query/23436/3 "2015-04-28T12:53:43Z")

</div>

On Tue, Apr 28, 2015 at 8:49 AM, Zaid Amir [redserpent7@gmail.com](mailto:redserpent7@gmail.com) wrote:

NVM, found the culprit.

> > 
> 
> Was missing a '.':
> 
> def str = ctx\_source.path; -\> def str = ctx\*.\*\_source.path;
> 
> Weird how there was nothing in the logs about this

+1. If you can make it reproduceable in a readable gist I'd file it as an  
issue. Groovy should be complaining about ctx\_source not being in scope.

Nik

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0yaupUzEWectNtV2NXObOgm5Ho8qx%2Bjkhpvjpi2bs3vg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0yaupUzEWectNtV2NXObOgm5Ho8qx%2Bjkhpvjpi2bs3vg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![redserpent7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redserpent7/32/467_2.png) [@redserpent7](https://discuss.elastic.co/u/redserpent7)
#### Post date: [April 29, 2015, 7:20am UTC](https://discuss.elastic.co/t/script-not-executing--update-by-query/23436/4 "2015-04-29T07:20:12Z")

</div>

Sorry for the delay was a bit occupied making sure everything worked as  
expected.

So here, I created a gist of the issue and hope it proves useful:

> <https://gist.github.com/redserpent7/e1d52afff435f3d759e1>

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/adf9c000-4dcf-453d-a623-f3b0fe40c227%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/adf9c000-4dcf-453d-a623-f3b0fe40c227%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [April 29, 2015, 10:17pm UTC](https://discuss.elastic.co/t/script-not-executing--update-by-query/23436/5 "2015-04-29T22:17:41Z")

</div>

Yup - still looks like a bug to me. I think the right thing to do is file  
it on github.

On Wed, Apr 29, 2015 at 3:20 AM, Zaid Amir [redserpent7@gmail.com](mailto:redserpent7@gmail.com) wrote:

> Sorry for the delay was a bit occupied making sure everything worked as  
> expected.
> 
> So here, I created a gist of the issue and hope it proves useful:
> 
> [ES example of groovy not throwing any exceptions when ctx.\_source is misspelled. · GitHub](https://gist.github.com/redserpent7/e1d52afff435f3d759e1)
> 
> --  
> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/adf9c000-4dcf-453d-a623-f3b0fe40c227%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/adf9c000-4dcf-453d-a623-f3b0fe40c227%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/adf9c000-4dcf-453d-a623-f3b0fe40c227%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/adf9c000-4dcf-453d-a623-f3b0fe40c227%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPmjWd2FUogdysP8R7YxdKCxddkn7SM-2Vk-bZBMFV5g-1T-dg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd2FUogdysP8R7YxdKCxddkn7SM-2Vk-bZBMFV5g-1T-dg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 12:16am UTC](https://discuss.elastic.co/t/script-not-executing--update-by-query/23436/6 "2017-07-06T00:16:52Z")

</div>


