内联脚本错误

时间:2016-09-26 10:29:32

标签: elasticsearch groovy

我正在尝试使用Inline Scripting运行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找不到记录器的appender   (org.elasticsearch.node)。 log4j:WARN请初始化log4j   系统正常。 log4j:警告请参阅   http://logging.apache.org/log4j/1.2/faq.html#noconfig了解更多信息。   java.lang.IllegalArgumentException:无法执行脚本   org.elasticsearch.action.update.UpdateHelper.executeScript(UpdateHelper.java:257)     在   org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:197)     在   org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:80)     在   org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:174)     在   org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:168)     在   org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:66)     在   org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction $ ShardTransportHandler.messageReceived(TransportInstanceSingleOperationAction.java:244)     在   org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction $ ShardTransportHandler.messageReceived(TransportInstanceSingleOperationAction.java:240)     在   org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)     在   org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75)     在   org.elasticsearch.transport.netty.MessageChannelHandler $ RequestHandler.doRun(MessageChannelHandler.java:300)     在   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)     在java.lang.Thread.run(未知来源)引起:   ScriptException [无法运行内联脚本[ctx._source.gender.value   = ctx._source ['AVG_PRICE_PER_UNIT']。value * ctx._source ['5']。value]使用lang [groovy]];嵌套:AssertionError [BUG!未捕获的异常:   member是私有的:java.lang.Integer.value / int / getField,from   org.codehaus.groovy.vmplugin.v7.IndyInterface];嵌套:   NotSerializableExceptionWrapper [illegal_access_exception:member is   private:java.lang.Integer.value / int / getField,from   org.codehaus.groovy.vmplugin.v7.IndyInterface];在   org.elasticsearch.script.groovy.GroovyScriptEngineService $ GroovyScript.run(GroovyScriptEngineService.java:320)     在   org.elasticsearch.action.update.UpdateHelper.executeScript(UpdateHelper.java:252)     ... 14更多引起:java.lang.AssertionError:BUG!未捕获   EXCEPTION:成员是私有的:java.lang.Integer.value / int / getField,   来自org.codehaus.groovy.vmplugin.v7.IndyInterface at   org.codehaus.groovy.vmplugin.v7.Selector $ PropertySelector.chooseMeta(Selector.java:311)     在   org.codehaus.groovy.vmplugin.v7.Selector $ MethodSelector.setCallSiteTarget(Selector.java:954)     在   org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:224)     在   a45669ea4b74cc2cb4371072fd14ab69cb5dd5f6.run(a45669ea4b74cc2cb4371072fd14ab69cb5dd5f6:1)     在   org.elasticsearch.script.groovy.GroovyScriptEngineService $ GroovyScript $ 1.run(GroovyScriptEngineService.java:313)     在java.security.AccessController.doPrivileged(Native Method)at   org.elasticsearch.script.groovy.GroovyScriptEngineService $ GroovyScript.run(GroovyScriptEngineService.java:310)     ... 15更多引起:   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(未知来源)at   java.lang.invoke.MethodHandles $ Lookup.checkAccess(未知来源)at   java.lang.invoke.MethodHandles $ Lookup.checkField(未知来源)at   java.lang.invoke.MethodHandles $ Lookup.getDirectFieldCommon(未知   来源)at   java.lang.invoke.MethodHandles $ Lookup.getDirectFieldNoSecurityManager(未知   来源)at   java.lang.invoke.MethodHandles $ Lookup.unreflectField(未知来源)     在java.lang.invoke.MethodHandles $ Lookup.unreflectGetter(未知   来源)at   org.codehaus.groovy.vmplugin.v7.Selector $ PropertySelector.chooseMeta(Selector.java:302)     ......还有21个

1 个答案:

答案 0 :(得分:0)

尝试此操作(即使用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();