Script not executing _update_by_query


(Zaid Amir) #1

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


(Zaid Amir) #2

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


(Nik Everett) #3

On Tue, Apr 28, 2015 at 8:49 AM, Zaid Amir 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0yaupUzEWectNtV2NXObOgm5Ho8qx%2Bjkhpvjpi2bs3vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Zaid Amir) #4

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:

--
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/adf9c000-4dcf-453d-a623-f3b0fe40c227%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Nik Everett) #5

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 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:

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.
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?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/CAPmjWd2FUogdysP8R7YxdKCxddkn7SM-2Vk-bZBMFV5g-1T-dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #6