elasticsearch - Java.lang.NullPointerException: Cannot get property ‘x’ on null object - when running a groovy script -
i run groovy script through transport client: script looks this:
if (ctx._source.field.names == null) ctx._source.field.names=newitems else ctx._source.field.names<< newitems; ctx._source.field.names = ctx._source.field.names.flatten().unique()
my problem of times works following error:
caused by: java.lang.illegalargumentexception: failed execute script @ org.elasticsearch.action.update.updatehelper.executescript(updatehelper.java:256) ~[org.elasticsearch.elasticsearch-2.0.1.jar:2.0.1] @ org.elasticsearch.action.update.updatehelper.prepare(updatehelper.java:196) ~[org.elasticsearch.elasticsearch-2.0.1.jar:2.0.1] @ org.elasticsearch.action.update.updatehelper.prepare(updatehelper.java:79) ~[org.elasticsearch.elasticsearch-2.0.1.jar:2.0.1] @ org.elasticsearch.action.update.transportupdateaction.shardoperation(transportupdateaction.java:170) ~[org.elasticsearch.elasticsearch-2.0 @ org.elasticsearch.action.update.transportupdateaction$3$1.dorun(transportupdateaction.java:227) ~[org.elasticsearch.elasticsearch-2.0.1. @ org.elasticsearch.common.util.concurrent.abstractrunnable.run(abstractrunnable.java:37) ~[org.elasticsearch.elasticsearch-2.0.1.jar:2.0.1] @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) ~[na:1.8.0_74-cedar14] @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) ~[na:1.8.0_74-cedar14] @ java.lang.thread.run(thread.java:745) ~[na:1.8.0_74-cedar14] caused by: org.elasticsearch.script.groovy.groovyscriptexecutionexception: failed run inline script [if (ctx._source.field.names == null) ctx._source.field.names=newitems else ctx._source.field.names<< newitems; ctx._source.field.names = ctx._source.field.names.flatten().unique()] using lang [groovy] @ org.elasticsearch.script.groovy.groovyscriptengineservice$groovyscript.run(groovyscriptengineservice.java:253) ~[org.elasticsearch. @ org.elasticsearch.action.update.updatehelper.executescript(updatehelper.java:251) ~[org.elasticsearch.elasticsearch-2.0.1.jar:2.0.1] ... 8 common frames omitted caused by: java.lang.nullpointerexception: cannot property 'names' on null object @ org.codehaus.groovy.runtime.nullobject.getproperty(nullobject.java:60) ~[org.codehaus.groovy.groovy-all-2.4.0.jar:2.4.0] @ org.codehaus.groovy.runtime.invokerhelper.getproperty(invokerhelper.java:172) ~[org.codehaus.groovy.groovy-all-2.4.0.jar:2.4.0] @ org.codehaus.groovy.runtime.callsite.nullcallsite.getproperty(nullcallsite.java:47) ~[org.codehaus.groovy.groovy-all-2.4.0.jar:2.4.0] @ org.codehaus.groovy.runtime.callsite.abstractcallsite.callgetproperty(abstractcallsite.java:296) ~[org.codehaus.groovy.groovy-all-2.4.0. @ 889babff0826c95e16279a9fb1fd2eb97a63e642.run(889babff0826c95e16279a9fb1fd2eb97a63e642:1) ~[na:na] @ org.elasticsearch.script.groovy.groovyscriptengineservice$groovyscript.run(groovyscriptengineservice.java:248) ~[org.elasticsearch.
here document example:
{ "field": { "names": ["a","b","c"], "a": { "name": "a awesome" }, "b": { "name": "b awesome" }, "c": { "name": "c awesome" } }, "email": "x@gmail.com" }
mappings:
"my_index": { "mappings": { "my_type": { "properties": { "email": { "type": "string", "analyzer": "email" }, "field": { "properties": { "a": { "properties": { "name": { "type": "string", "analyzer": "lowercase" } } }, "b": { "properties": { "name": { "type": "string", "analyzer": "lowercase" } } }, "c": { "properties": { "name": { "type": "string", "analyzer": "lowercase" } } }, "names": { "type": "string", "analyzer": "lowercase" } } } } } } }
my code:
override def addterms(id: string, path: string, terms: set[string]): future[unit] = { val groovyscript = s"""if (ctx._source.$path == null) | ctx._source.$path=newitems |else | ctx._source.$path<< newitems; |ctx._source.$path = ctx._source.$path.flatten().unique();""".stripmargin client.execute(elasticdsl.update id id in indexname / documenttype retryonconflict 5 script { script(groovyscript).params(map("newitems" -> terms.toarray)) }).map(_ => unit) } override def update(id: string, field: nestedfieldvalue) = { client.execute { elasticdsl.update(id) in indexname / documenttype retryonconflict 5 doc field } }
i looked on document script fails on, , tried manually run script using curl, , worked. document not problem.
i running update 38 documents, meaning run 38 times. exception thrown on different document every time try update beginning (meaning running again on 38 documents)
not sure missing here. ideas? thanks!
Comments
Post a Comment