I am migrating a java application from elastic search high level client to java api client. There is a SearchTemplateRequest class in elastic search java high level client. But I couldn't find any corresponding class in java api client. Can someone help on this? Old code snippet is as below.
public SearchTemplateResponse getScriptResponse(String indexName, String scriptName, Map<String, Object> scriptParams) throws IOException {
SearchTemplateRequest request = null;
SearchTemplateResponse response = null;
try {
SearchTemplateRequest request = new SearchTemplateRequest();
request.setRequest(new SearchRequest(new String[] { indexName }, trackTotalHitsSourceBuilder()));
request.setScriptType(ScriptType.STORED);
request.setScript(scriptName);
request.setScriptParams(scriptParams);
request.getRequest().source().trackTotalHits();
response = getClient().searchTemplate(request, RequestOptions.DEFAULT);
} catch (Exception e) {
throw e;
}
return response;
}
I'm using above code block to get the response of bucket aggregation with script query.
I recommend read the Getting Started Java API Client.
For create first connection read the link.
Example using script and updateByQuery: