ClasscastException when using SearchTemplateRequestBuilder from within a plugin


(Nicolas Giraud) #1

Hi,

I have written an action plugin in which I need to call a search template.

The code is quite straightforward:

SearchResponse sr = new SearchTemplateRequestBuilder(client)
        .setScript("myTemplate")                       
        .setScriptType(ScriptType.STORED)     
        .setScriptParams(template_params)                   
        .setRequest(new SearchRequest("myIndex").types("myType")                    
        .get()                                              
        .getResponse();            

I can install the plugin, however when running this code (from within a class extending BaseRestHandler),
I get the following exception:

java.lang.ClassCastException: org.elasticsearch.script.mustache.SearchTemplateRequest cannot be cast to org.elasticsearch.script.mustache.SearchTemplateRequest
at org.elasticsearch.script.mustache.TransportSearchTemplateAction.doExecute(TransportSearchTemplateAction.java:53) ~[?:?]
at org.elasticsearch.action.support.TransportAction.doExecute(TransportAction.java:146) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.action.support.TransportAction$RequestFilterChain.proceed(TransportAction.java:170) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:142) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:84) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.client.node.NodeClient.executeLocally(NodeClient.java:83) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.client.node.NodeClient.doExecute(NodeClient.java:72) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62) ~[elasticsearch-5.6.7.jar:5.6.7]
at com.doodle.myplugin.action.FullTextSearchAction.handleQuery(FullTextSearchAction.java:81) ~[?:?]

I have the following dependency in the classpath: org.codelibs.elasticsearch.module:lang-mustache:5.6.7. The same happens if I use org.elasticsearch.plugin:lang-mustache-client instead. I'm puzzled at which dependency to pick by the way!

If I declare the dependency as provided, I get a ClassNotFoundException.

I'm pretty stuck at this point...

Any help in solving this would be greatly appreciated!


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.