I'm having an issue calling a .js file from an update request processor chain. The purpose of this is to parse some information from a field and put it into another. Unfortunately, it's giving a NoSuchMethodException.
On indexing, I'm getting this error:
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","java.lang.NoSuchMethodException"],
"msg":"Unable to invoke function finish in script: /var/solr/data/nma3/conf/updateProcessor.js: No such function finish",
"trace":"org.apache.solr.common.SolrException: Unable to invoke function finish in script: /var/solr/data/nma3/conf/updateProcessor.js: No such function finish\n\tat org.apache.solr.update.processor.StatelessScriptUpdateProcessorFactory$ScriptUpdateProcessor.invokeFunctionUnsafe(StatelessScriptUpdateProcessorFactory.java:468)\n\tat org.apache.solr.update.processor.StatelessScriptUpdateProcessorFactory$ScriptUpdateProcessor.access$300(StatelessScriptUpdateProcessorFactory.java:385)\n\tat org.apache.solr.update.processor.StatelessScriptUpdateProcessorFactory$ScriptUpdateProcessor$1.run(StatelessScriptUpdateProcessorFactory.java:447)
In solrconfig.xml:
Here is the URH:
<requestHandler name="/update" class="solr.UpdateRequestHandler">
<lst name="defaults">
<str name="update.chain">update_chain</str>
</lst>
</requestHandler>
And the URP Chain:
<updateRequestProcessorChain name="update_chain" default="true">
<processor class="solr.StatelessScriptUpdateProcessorFactory">
<str name="script">updateProcessor.js</str>
</processor>
<processor class="solr.RunUpdateProcessorFactory"/>
<processor class="solr.LogUpdateProcessorFactory"/>
</updateRequestProcessorChain>
And in the same folder (conf), updateProcessor.js consists of:
function processAdd(cmd) {
doc = cmd.solrDoc;
field = doc.getFieldValue("id");
desired_val = field.split("/")[3];
doc.setField("split", desired_val);
}
I've tried a few things and I'm stuck. Any help is appreciated. Thanks
You have to define functions for each of the expected method names from the update processor API:
Each script file is expected to declare functions with the same name as each method in UpdateRequestProcessor, using the same arguments. One slight deviation is in the optional return value from these functions: If a script function has a boolean return value, and that value is false then the processor will cleanly terminate processing of the command and return, without forwarding the command on to the next script or processor in the chain. Due to limitations in the ScriptEngine API used by this factory, it can not enforce that all functions exist on initialization, so errors from missing functions will only be generated at runtime when the chain attempts to use them.
The error message says that you haven't defined a function named finish
with the processor expects to be there - which seems to be correct from the javascript file you've included.
You can see the complete list of methods that you should implement in the API docs for UpdateRequestProcessor
.
You might be able to skip a few of those (doClose
is protected and you're not inheriting, so that one should be skippable), but generally you should at least include a skeleton function for all the defined methods:
void close()
protected void doClose()
void finish()
void processAdd(AddUpdateCommand cmd)
void processCommit(CommitUpdateCommand cmd)
void processDelete(DeleteUpdateCommand cmd)
void processMergeIndexes(MergeIndexesCommand cmd)
void processRollback(RollbackUpdateCommand cmd)