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:
Map<String, JsonData> params = Map.of("key", JsonData.of("value"));
Script script = new Script.Builder()
.stored(StoredScriptId.of(ssi -> ssi.id("script_name").params(params)))
.build();
UpdateByQueryRequest updateByQueryRequest = UpdateByQueryRequest.of(
up -> up.index("idx_script_tst")
.query(Query.of(q -> q.matchAll(MatchAllQuery.of(maq -> maq))))
.script(script));
var updateResponse = client.updateByQuery(updateByQueryRequest);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.