# SearchTemplate issue Java API

**URL:** <https://discuss.elastic.co/t/searchtemplate-issue-java-api/256185>\
**Category:** Elasticsearch\
**Created:** [November 20, 2020, 7:57pm UTC](https://discuss.elastic.co/t/searchtemplate-issue-java-api/256185 "2020-11-20T19:57:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mombasa](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@Mombasa](https://discuss.elastic.co/u/Mombasa)\
**Post date:** [November 20, 2020, 7:57pm UTC](https://discuss.elastic.co/t/searchtemplate-issue-java-api/256185/1 "2020-11-20T19:57:45Z")

</div>

I'm stuck with a SearchTemplate request, until now I've been able to write queries thru the QueryBuilder and execute them calling the "search" method of the RestHighLevelClient java client, but when I try to execute the "searchTemplate" method I get a parse exception from the server "request body or source parameter is required".

So far I've been reading the documentation but nothing, the guide about the "searchTemplate" is very poor.

This is how I'm currently trying to follow the basic steps from the official documentation:

```auto
     SearchTemplateRequest request = new SearchTemplateRequest();
        request.setRequest(new SearchRequest(indexPI));

        request.setScriptType(ScriptType.INLINE);
        request.setScript( "{" +
                " \"query\": { \"match\" : { \"{{field}}\" : \"{{value}}\" } }," +
                " \"size\" : \"{{size}}\"" +
                "}");

        Map<String, Object> scriptParams = new HashMap<>();

        scriptParams.put("from","");
        scriptParams.put("size","");
        scriptParams.put("field", "title");
        scriptParams.put("value", "elasticsearch");
        scriptParams.put("size", 5);
        request.setScriptParams(scriptParams);

        SearchTemplateResponse response = elasticSearchClient.searchTemplate(request, 
        RequestOptions.DEFAULT);

```

The error I get :

```auto
    Elasticsearch exception [type=parse_exception, reason=request body or source parameter is required]

```

At this point I'm trying to understand how to set the request body for the above request and actually wondering if it is possibile to do.

Any clue about what is missing besides the "unsettable" request body from the exception?

Update: If I try the same request to my local elasticSearch node everything works fine. Got the right document, so at this point I've got no idea what's the problem. So far I've verified the request is correct, otherwise I will get the same error message from the local node.

---

<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 18, 2020, 7:58pm UTC](https://discuss.elastic.co/t/searchtemplate-issue-java-api/256185/2 "2020-12-18T19:58:00Z")

</div>

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