# 5.0.0-alpha5: Java API to execute search template queries

**URL:** <https://discuss.elastic.co/t/5-0-0-alpha5-java-api-to-execute-search-template-queries/60414>\
**Category:** Elasticsearch\
**Created:** [September 13, 2016, 5:30pm UTC](https://discuss.elastic.co/t/5-0-0-alpha5-java-api-to-execute-search-template-queries/60414 "2016-09-13T17:30:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Potts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeff_potts/32/1047_2.png) [@Jeff\_Potts](https://discuss.elastic.co/u/Jeff_Potts)\
**Post date:** [September 13, 2016, 5:30pm UTC](https://discuss.elastic.co/t/5-0-0-alpha5-java-api-to-execute-search-template-queries/60414/1 "2016-09-13T17:30:30Z")

</div>

Prior to 5.0.0-alpha4 you could use the Java API to execute a search template like this:

```
        Template template = new Template("some-template-id", ScriptService.ScriptType.FILE, null, null, params);

        SearchRequestBuilder request = readClient.prepareSearch(index)
                .setTemplate(template);
        
        SearchResponse response = request.execute().actionGet();

```

In 5.0.0-alpha4, the setTemplate() method on SearchRequestBuilder was removed, and, according to the [commit](https://github.com/elastic/elasticsearch/commits/50b47aa9303c66396955e13c166fb48466be4f0a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java), all of the search template related API was relocated.

I've tried looking in the unit tests to see if there are any examples of file based search templates getting executed, but I haven't had luck so far.

Does anyone know how to do the equivalent of the above using what's now available in 5.0.0-alpha5?

---

<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:** [July 5, 2017, 10:20pm UTC](https://discuss.elastic.co/t/5-0-0-alpha5-java-api-to-execute-search-template-queries/60414/2 "2017-07-05T22:20:32Z")

</div>


