基于SearchTemplateRequest 实现。支持参数替换。
SearchTemplateRequest request = new SearchTemplateRequest();
request.setRequest(new SearchRequest(INDEX_NAME));
request.setScriptType(ScriptType.INLINE);
request.setScript(querySql);
Map<String, Object> scriptParams = new HashMap<>();
request.setScriptParams(scriptParams);
实现调用
SearchTemplateResponse searchTemplateResponse = elasticsearchRestTemplate.getClient().searchTemplate(request, RequestOptions.DEFAULT);
SearchResponse response = searchTemplateResponse.getResponse();