I am trying to use a filescript for an update operation for elastic search. The filescript I am using is a javascript and I am not able to understand why its compilation fails. Following is the file:
update-htext.js:
import org.elasticsearch.common.logging.*;
var level = org.apache.log4j.Level.INFO;
ESLogger logger=ESLoggerFactory.getLogger('myscript');
if(ctx._source.hTexts == null){
ctx._source.hTexts = [sourcehtext];
return;
}else{
var i = 0;
for(it in ctx._source.hTexts){
if(it.htext.contains(sourcehtext.htext)){
logger.logger.log(level,"Already Contains "+it.htext);
return;
}
if(sourcehtext.htext.contains(it.htext)){
logger.logger.log(level,"Updating "+it.htext);
break;
}
i++;
}
ctx._source.hTexts[i] = sourcehtext;
}
And I am invoking it as follows:
{
"script" :{
"script_id" : "update-htext",
"params" : {
"sourcehtext":{
"aid":1000,
"htext" : "and"
}
},
"lang" : "javascript"
}
}
I get the following error when elasticsearch starts and tries to index this js file:
org.mozilla.javascript.EvaluatorException: missing ; before statement (Script2.j
s#1)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultError
Reporter.java:77)
at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporte
r.java:64)