SearchTemplate issue Java API

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:

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

        request.setScript( "{" +
                "  \"query\": { \"match\" : { \"{{field}}\" : \"{{value}}\" } }," +
                "  \"size\" : \"{{size}}\"" +

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

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

        SearchTemplateResponse response = elasticSearchClient.searchTemplate(request, 

The error I get :

    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.

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