-1

my groovy script is something like this code:

def value=DynamicValue     
def Nvalue=NewValue
def field=Fieldvalue
def prod

NewValue=NewValue.toInteger()
prod=doc[''+DynamicValue+''].value*NewValue         
if(._source.doc[''+Fieldvalue+''].value != null) {
    ._source.doc[''+Fieldvalue+''].value=prod
}

I am trying to update the value of a field in my elasticsearch index like

._source.doc[''+Fieldvalue+''].value=prod

where AVG_PRICE_PER_UNIT is a field in my index.

But when i am exceuting it from java i get

  "reason" : {
            "type" : "script_exception",
            "reason" : "failed to run file script [fieldScript] using lang [groovy]",
            "caused_by" : {
              "type" : "illegal_argument_exception",
              "reason" : "argument type mismatch"
            }

is there any solution??

My Java code:

Map<String, Object> params = ImmutableMap.of("DynamicValue",AggregateValue_First, "NewValue", AggregateValue_Second, "Fieldvalue",hash); 
try { 
    SearchResponse Se = client.prepareSearch(indexName) 
        .addScriptField("checkValue", new Script("fieldScript", ScriptType.FILE, "groovy", params))
        .execute().actionGet(); 
        System.out.println(Se.toString()); 
} catch(RuntimeException e) { 
    e.printStackTrace(); 
}

my log shows

      if (._source.doc[''+Fieldvalue+''] != null) {_source.doc[''+Fieldvalue+''].value=prod}
     ^

1 error ]; at org.elasticsearch.script.groovy.GroovyScriptEngineService.compile(GroovyScriptEngineService.java:198) at org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileInit(ScriptService.java:549) at org.elasticsearch.script.ScriptService$ScriptChangesListener.onFileChanged(ScriptService.java:580) at org.elasticsearch.watcher.FileWatcher$FileObserver.onFileChanged(FileWatcher.java:279) at org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:131) at org.elasticsearch.watcher.FileWatcher$FileObserver.updateChildren(FileWatcher.java:215) at org.elasticsearch.watcher.FileWatcher$FileObserver.checkAndNotify(FileWatcher.java:117) at org.elasticsearch.watcher.FileWatcher.doCheckAndNotify(FileWatcher.java:70) at org.elasticsearch.watcher.AbstractResourceWatcher.checkAndNotify(AbstractResourceWatcher.java:44) at org.elasticsearch.watcher.ResourceWatcherService$ResourceMonitor.run(ResourceWatcherService.java:187) at org.elasticsearch.threadpool.ThreadPool$LoggingRunnable.run(ThreadPool.java:640) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.runAndReset(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) 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: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: 895843a31627edca5a53c198e26b4f4b13aa65c5: 26: unexpected token: . @ line 26, column 7.

11
  • Can you show the full query you're running? And maybe share a sample doc and/or mapping. Commented Sep 22, 2016 at 12:57
  • It is purely java code ,where i pass the parameters Commented Sep 23, 2016 at 5:35
  • What error do you see in the ES logs? Commented Sep 23, 2016 at 5:43
  • In your elasticsearch logs, what errors do you see? Commented Sep 23, 2016 at 6:43
  • You should preferably update your question with that info in order to make it more legible. Comments are not appropriate for that. Commented Sep 23, 2016 at 6:51

1 Answer 1

0

You have a typo in your script, change it to this:

def value=DynamicValue     
def Nvalue=NewValue
def field=Fieldvalue
def prod

NewValue=NewValue.toInteger()
prod=ctx._source[DynamicValue].value * NewValue         
if(ctx._source[Fieldvalue].value != null) {
    ctx._source[Fieldvalue].value=prod
}
Sign up to request clarification or add additional context in comments.

13 Comments

Thanks @Val,but this was the previous case for which i was getting 'argument mismatch exception'. Forget about this , how do you change the value of a field using a script? can you please tell me?
What do you mean by "previous case"? This should answer what you have in your question. If you have a different question, feel free to ask another one, but let's not mix two different things together.
i changed the code ,but still i am getting illegal argument exception
What error do you get now after changing the script? Update your question with the ES log you're receiving.
I just get "illegal_argument_exception" , the log seems to be empty, Val, Can you suggest me on how to update the field?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.