# Elasticsearch 5.0 SearchTemplate query Error

**URL:** <https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001>\
**Category:** Elasticsearch\
**Created:** [November 23, 2016, 3:05pm UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001 "2016-11-23T15:05:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![banu](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@banu](https://discuss.elastic.co/u/banu)\
**Post date:** [November 23, 2016, 3:05pm UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/1 "2016-11-23T15:05:09Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [November 23, 2016, 3:17pm UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/2 "2016-11-23T15:17:47Z")

</div>

Can you post the actual content of the stored template you are using (the one referred to by "template\_gender" above?

My suspicion is that something goes wrong when that is compiled to an actual ES query.

---

<div class="post-metadata">

**Author:** ![banu](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@banu](https://discuss.elastic.co/u/banu)\
**Post date:** [November 24, 2016, 5:24am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/3 "2016-11-24T05:24:39Z")

</div>

Please find the below stored template  
{  
"lang": "mustache",  
"\_id": "template\_gender",  
"found": true,  
"template": "{"query":{"match":{"tittle":"{{query\_string}}"}}}"  
}

---

<div class="post-metadata">

**Author:** ![banu](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@banu](https://discuss.elastic.co/u/banu)\
**Post date:** [November 24, 2016, 8:57am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/4 "2016-11-24T08:57:09Z")

</div>

Fixed the issue the problem here is the "template": "{"query":{"match":{"tittle":"{{query\_string}}"}}}" "query:" should be omitted.

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [November 24, 2016, 9:52am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/5 "2016-11-24T09:52:35Z")

</div>

Great to hear you could fix your issue.

Isabel

---

<div class="post-metadata">

**Author:** ![banu](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@banu](https://discuss.elastic.co/u/banu)\
**Post date:** [November 24, 2016, 9:56am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/6 "2016-11-24T09:56:03Z")

</div>

How to run this query from java API POST /\_search/template/lookup\_temp  
{  
"template": {  
"match":  
{  
"(city\_key":"({{nme}})^50 OR (name:({{nmewoe}}))^30 )"  
}

```
    }

```

}

Getting error when running this template query from java client API

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [November 24, 2016, 9:57am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/7 "2016-11-24T09:57:45Z")

</div>

What kind of error does the Java API give you?

---

<div class="post-metadata">

**Author:** ![banu](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@banu](https://discuss.elastic.co/u/banu)\
**Post date:** [November 24, 2016, 10:00am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/8 "2016-11-24T10:00:28Z")

</div>

No Error but getting zero results {"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max\_score":null,"hits":[]}}

Even when i have data in the name which i use to query.

---

<div class="post-metadata">

**Author:** ![banu](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@banu](https://discuss.elastic.co/u/banu)\
**Post date:** [November 25, 2016, 6:27am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/9 "2016-11-25T06:27:51Z")

</div>

Can you provide some suggestions on this

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 23, 2016, 6:28am UTC](https://discuss.elastic.co/t/elasticsearch-5-0-searchtemplate-query-error/67001/10 "2016-12-23T06:28:20Z")

</div>

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