# What replaced SearchRequest.templateSource()?

**URL:** <https://discuss.elastic.co/t/what-replaced-searchrequest-templatesource/99914>\
**Category:** Elasticsearch\
**Created:** [September 9, 2017, 4:25am UTC](https://discuss.elastic.co/t/what-replaced-searchrequest-templatesource/99914 "2017-09-09T04:25:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![svanschalkwyk](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@svanschalkwyk](https://discuss.elastic.co/u/svanschalkwyk)\
**Post date:** [September 9, 2017, 4:25am UTC](https://discuss.elastic.co/t/what-replaced-searchrequest-templatesource/99914/1 "2017-09-09T04:25:40Z")

</div>

I'm migrating a RestAction plugin from ES 2.0 to 5.5.  
I'm stuck at this line for now:  
searchRequest.templateSource()  
Prior to this the original plugin goes through some acrobatics to modify the query, change the template to query etc.  
The original can be found here: [https://svn.apache.org/repos/asf/manifoldcf/integration/elasticsearch-2.0/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/](https://svn.apache.org/repos/asf/manifoldcf/integration/elasticsearch-2.0/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/)  
and the offending file/line is MCFAuthorizerRestSearchAction.java line (arounbd) 114.  
Any help would be much appreciated.  
Also, if I should be using some other path to get to a better result, please suggest it.  
Thank you.

'try {  
requestJSON = objectMapper.readTree(RestActions.getRestContent(request).toBytes());  
if (isTemplateRequest) {  
modifiedJSON = (ObjectNode) requestJSON;  
innerJSON = (ObjectNode)requestJSON.findValue("template");  
filteredQueryBuilder = QueryBuilders.filteredQuery(QueryBuilders.wrapperQuery(innerJSON.findValue("query").toString()), authorizationFilter);  
modifiedJSON.replace("template",innerJSON.set("query", objectMapper.readTree(filteredQueryBuilder.buildAsBytes().toBytes())));  
searchRequest.templateSource(modifiedJSON.toString());  
} else {  
filteredQueryBuilder = QueryBuilders.filteredQuery(QueryBuilders.wrapperQuery(requestJSON.findValue("query").toString()), authorizationFilter);  
modifiedJSON = (ObjectNode) requestJSON;  
modifiedJSON.set("query", objectMapper.readTree(filteredQueryBuilder.buildAsBytes().toBytes()));  
searchRequest.source(modifiedJSON.toString());  
}  
} catch (IOException e) {  
throw new MCFAuthorizerException("JSON parser error: "+e.getMessage(), e);  
}`

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 11, 2017, 7:12am UTC](https://discuss.elastic.co/t/what-replaced-searchrequest-templatesource/99914/2 "2017-09-11T07:12:44Z")

</div>

You might want to take a look at `SearchTemplateRequest`

---

<div class="post-metadata">

**Author:** ![svanschalkwyk](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@svanschalkwyk](https://discuss.elastic.co/u/svanschalkwyk)\
**Post date:** [September 11, 2017, 3:57pm UTC](https://discuss.elastic.co/t/what-replaced-searchrequest-templatesource/99914/3 "2017-09-11T15:57:17Z")

</div>

Thank you!

---

<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:** [October 9, 2017, 3:57pm UTC](https://discuss.elastic.co/t/what-replaced-searchrequest-templatesource/99914/4 "2017-10-09T15:57:30Z")

</div>

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