本文整理了Java中org.elasticsearch.client.Client.multiSearch()
方法的一些代码示例,展示了Client.multiSearch()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Client.multiSearch()
方法的具体详情如下:
包路径:org.elasticsearch.client.Client
类名称:Client
方法名:multiSearch
[英]Performs multiple search requests.
[中]执行多个搜索请求。
代码示例来源:origin: NLPchina/elasticsearch-sql
private int combineResultsFromMultiResponses(List<SearchHit> combinedResults, int totalLimit, int currentCombinedResults, SearchHit[] hits, int currentIndex, MultiSearchRequest multiSearchRequest) {
MultiSearchResponse.Item[] responses = client.multiSearch(multiSearchRequest).actionGet().getResponses();
String t1Alias = nestedLoopsRequest.getFirstTable().getAlias();
String t2Alias = nestedLoopsRequest.getSecondTable().getAlias();
for(int j =0 ; j < responses.length && currentCombinedResults < totalLimit ; j++){
SearchHit hitFromFirstTable = hits[currentIndex+j];
onlyReturnedFields(hitFromFirstTable.getSourceAsMap(), nestedLoopsRequest.getFirstTable().getReturnedFields(),nestedLoopsRequest.getFirstTable().getOriginalSelect().isSelectAll());
SearchResponse multiItemResponse = responses[j].getResponse();
updateMetaSearchResults(multiItemResponse);
//todo: if responseForHit.getHits.length < responseForHit.getTotalHits(). need to fetch more!
SearchHits responseForHit = multiItemResponse.getHits();
if(responseForHit.getHits().length == 0 && nestedLoopsRequest.getJoinType() == SQLJoinTableSource.JoinType.LEFT_OUTER_JOIN){
SearchHit unmachedResult = createUnmachedResult(nestedLoopsRequest.getSecondTable().getReturnedFields(), currentCombinedResults, t1Alias, t2Alias, hitFromFirstTable);
combinedResults.add(unmachedResult);
currentCombinedResults++;
continue;
}
for(SearchHit matchedHit : responseForHit.getHits() ){
SearchHit searchHit = getMergedHit(currentCombinedResults, t1Alias, t2Alias, hitFromFirstTable, matchedHit);
combinedResults.add(searchHit);
currentCombinedResults++;
if(currentCombinedResults >= totalLimit) break;
}
if(currentCombinedResults >= totalLimit) break;
}
return currentCombinedResults;
}
代码示例来源:origin: javanna/elasticshell
@Override
protected ActionFuture<MultiSearchResponse> doExecute(MultiSearchRequest request) {
return client.multiSearch(request);
}
代码示例来源:origin: com.floragunn/search-guard
protected void doGet(final MultiGetRequest request, final ActionListener listener, final Client client) {
client.multiSearch(toMultiSearchRequest(request), new DelegatingActionListener<MultiSearchResponse, GetResponse>(listener) {
@Override
public GetResponse getDelegatedFromInstigator(final MultiSearchResponse searchResponse) {
if (searchResponse.getResponses() == null || searchResponse.getResponses().length <= 0) {
final Item item = request.getItems().get(0);
return new GetResponse(new GetResult(item.index(), item.type(), item.id(), item.version(), false, null, null));
} else if (searchResponse.getResponses().length > 1) {
throw new RuntimeException("cannot happen");
} else {
final org.elasticsearch.action.search.MultiSearchResponse.Item item = searchResponse.getResponses()[0];
final SearchHit sh = item.getResponse().getHits().getHits()[0];
return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null));
}
}
});
}
代码示例来源:origin: com.floragunn/search-guard
client.multiSearch(toMultiSearchRequest((MultiGetRequest) request), listener);
this.doGet((MultiGetRequest) request, listener, client);
return;
代码示例来源:origin: org.nlpcn/elasticsearch-sql
private int combineResultsFromMultiResponses(List<SearchHit> combinedResults, int totalLimit, int currentCombinedResults, SearchHit[] hits, int currentIndex, MultiSearchRequest multiSearchRequest) {
MultiSearchResponse.Item[] responses = client.multiSearch(multiSearchRequest).actionGet().getResponses();
String t1Alias = nestedLoopsRequest.getFirstTable().getAlias();
String t2Alias = nestedLoopsRequest.getSecondTable().getAlias();
for(int j =0 ; j < responses.length && currentCombinedResults < totalLimit ; j++){
SearchHit hitFromFirstTable = hits[currentIndex+j];
onlyReturnedFields(hitFromFirstTable.getSourceAsMap(), nestedLoopsRequest.getFirstTable().getReturnedFields(),nestedLoopsRequest.getFirstTable().getOriginalSelect().isSelectAll());
SearchResponse multiItemResponse = responses[j].getResponse();
updateMetaSearchResults(multiItemResponse);
//todo: if responseForHit.getHits.length < responseForHit.getTotalHits(). need to fetch more!
SearchHits responseForHit = multiItemResponse.getHits();
if(responseForHit.getHits().length == 0 && nestedLoopsRequest.getJoinType() == SQLJoinTableSource.JoinType.LEFT_OUTER_JOIN){
SearchHit unmachedResult = createUnmachedResult(nestedLoopsRequest.getSecondTable().getReturnedFields(), currentCombinedResults, t1Alias, t2Alias, hitFromFirstTable);
combinedResults.add(unmachedResult);
currentCombinedResults++;
continue;
}
for(SearchHit matchedHit : responseForHit.getHits() ){
SearchHit searchHit = getMergedHit(currentCombinedResults, t1Alias, t2Alias, hitFromFirstTable, matchedHit);
combinedResults.add(searchHit);
currentCombinedResults++;
if(currentCombinedResults >= totalLimit) break;
}
if(currentCombinedResults >= totalLimit) break;
}
return currentCombinedResults;
}
代码示例来源:origin: harbby/presto-connectors
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
String[] types = Strings.splitStringByCommaToArray(request.param("type"));
String path = request.path();
boolean isTemplateRequest = isTemplateRequest(path);
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions());
multiSearchRequest.add(RestActions.getRestContent(request), isTemplateRequest, indices, types, request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex);
client.multiSearch(multiSearchRequest, new RestToXContentListener<MultiSearchResponse>(channel));
}
内容来源于网络,如有侵权,请联系作者删除!