We are trying to use the search template and get the search results. Can anyone suggest a solution for this.
Attached the error what we are getting
package elastic5;
.
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.mustache.TemplateQueryBuilder;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class ElasticTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
// on startup
TransportClient client;
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch").build();
try {
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
Map<String, Object> template_params = new HashMap<>();
template_params.put("query_string", "aaaaa");
QueryBuilder qb = new TemplateQueryBuilder(
"template_gender",
ScriptService.ScriptType.STORED,
template_params);
SearchResponse response = client.prepareSearch()
.setIndices("twitter")
.setTypes("canidate")
.setQuery(qb).execute().actionGet();
System.out.println(response.getHits());
// on shutdown
System.out.println("SUCEESSS");
System.out.println(client.nodeName());
client.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Error we are getting :
Failed to execute phase [query_fetch], all shards failed; shardFailures {[IhhQQOkrSaKlWju_L_ZRNg][twitter][0]: RemoteTransportException[[IhhQQOk][127.0.0.1:9300][indices:data/read/search[phase/query+fetch]]]; nested: ParsingException[no [query] registered for [query]]; }org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1033)
at org.elasticsearch.transport.TransportService$6.onFailure(TransportService.java:559)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.onFailure(ThreadContext.java:490)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: RemoteTransportException[[IhhQQOk][127.0.0.1:9300][indices:data/read/search[phase/query+fetch]]]; nested: ParsingException[no [query] registered for [query]];
Caused by: ParsingException[no [query] registered for [query]]
Searched and we could not find any solution for this can somebody help us on this ?