我正在尝试使用内联脚本运行Update api,我的代码是
client.prepareUpdate("result",typeName, "1") .setScript(new Script("ctx._source.gender=doc['"+AggregateValue_First+"'].value*doc['"+AggregateValue_Second+"'].value",ScriptType.INLINE, null, null)) .get();
当我执行它时,我得到
java.lang.IllegalArgumentException: failed to execute script
我的日志看起来像
Caused by: ScriptException[failed to run inline script [ctx._source.gender = doc['AVG_PRICE_PER_UNIT'].value*doc['NUMBER_OF_UNITS'].value] using lang [groovy]]; nested: NotSerializableExceptionWrapper[missing_property_exception: No such property: doc for class: af9b76c11012333a0eeba6af6df35125322f36b8]; at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:320) at org.elasticsearch.action.update.UpdateHelper.executeScript(UpdateHelper.java:252)... 14 more Caused by: NotSerializableExceptionWrapper[missing_property_exception: No such property: doc for class: af9b76c11012333a0eeba6af6df35125322f36b8] at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.vmplugin.v7.IndyGuardsFiltersAndSignatures.unwrap(IndyGuardsFiltersAndSignatures.java:177) at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:228) at af9b76c11012333a0eeba6af6df35125322f36b8.run(af9b76c11012333a0eeba6af6df35125322f36b8:1) at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript$1.run(GroovyScriptEngineService.java:313) at java.security.AccessController.doPrivileged(Native Method) at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:310) ... 15 more
有人可以帮我弄这个吗?
我试过了
client.prepareUpdate(“ result”,typeName,“ 1”)。setScript(newScript(“ ctx._source.gender.value = ctx._source [‘” + AggregateValue_First +“’]。value * ctx._source [‘” + AggregateValue_Second + “’] .value”,ScriptType.INLINE,null,null)).get();
现在错误是这样的
log4j:WARN No appenders could be found for logger (org.elasticsearch.node). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. java.lang.IllegalArgumentException: failed to execute script at org.elasticsearch.action.update.UpdateHelper.executeScript(UpdateHelper.java:257) at org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:197) at org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:80) at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:174) at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:168) at org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:66) at org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction$ShardTransportHandler.messageReceived(TransportInstanceSingleOperationAction.java:244) at org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction$ShardTransportHandler.messageReceived(TransportInstanceSingleOperationAction.java:240) at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33) at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75) at org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.doRun(MessageChannelHandler.java:300) at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: ScriptException[failed to run inline script [ctx._source.gender.value = ctx._source[‘AVG_PRICE_PER_UNIT’].value * ctx._source[‘5’].value] using lang [groovy]]; nested: AssertionError[BUG! UNCAUGHT EXCEPTION: member is private: java.lang.Integer.value/int/getField, from org.codehaus.groovy.vmplugin.v7.IndyInterface]; nested: NotSerializableExceptionWrapper[illegal_access_exception: member is private: java.lang.Integer.value/int/getField, from org.codehaus.groovy.vmplugin.v7.IndyInterface]; at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:320) at org.elasticsearch.action.update.UpdateHelper.executeScript(UpdateHelper.java:252) … 14 more Caused by: java.lang.AssertionError: BUG! UNCAUGHT EXCEPTION: member is private: java.lang.Integer.value/int/getField, from org.codehaus.groovy.vmplugin.v7.IndyInterface at org.codehaus.groovy.vmplugin.v7.Selector$PropertySelector.chooseMeta(Selector.java:311) at org.codehaus.groovy.vmplugin.v7.Selector$MethodSelector.setCallSiteTarget(Selector.java:954) at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:224) at a45669ea4b74cc2cb4371072fd14ab69cb5dd5f6.run(a45669ea4b74cc2cb4371072fd14ab69cb5dd5f6:1) at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript$1.run(GroovyScriptEngineService.java:313) at java.security.AccessController.doPrivileged(Native Method) at org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript.run(GroovyScriptEngineService.java:310) … 15 more Caused by: NotSerializableExceptionWrapper[illegal_access_exception: member is private: java.lang.Integer.value/int/getField, from org.codehaus.groovy.vmplugin.v7.IndyInterface] at java.lang.invoke.MemberName.makeAccessException(Unknown Source) at java.lang.invoke.MethodHandles$Lookup.checkAccess(Unknown Source) at java.lang.invoke.MethodHandles$Lookup.checkField(Unknown Source) at java.lang.invoke.MethodHandles$Lookup.getDirectFieldCommon(Unknown Source) at java.lang.invoke.MethodHandles$Lookup.getDirectFieldNoSecurityManager(Unknown Source) at java.lang.invoke.MethodHandles$Lookup.unreflectField(Unknown Source) at java.lang.invoke.MethodHandles$Lookup.unreflectGetter(Unknown Source) at org.codehaus.groovy.vmplugin.v7.Selector$PropertySelector.chooseMeta(Selector.java:302) … 21 more
尝试以下操作(即使用ctx._source代替doc):
ctx._source
doc
client.prepareUpdate("result",typeName, "1") .setScript(new Script("ctx._source.gender = ctx._source['"+AggregateValue_First+"'] * ctx._source['"+AggregateValue_Second+"']", ScriptType.INLINE, null, null)) .get();