本文整理匯總了Java中org.elasticsearch.client.Client.search方法的典型用法代碼示例。如果您正苦於以下問題:Java Client.search方法的具體用法?Java Client.search怎麽用?Java Client.search使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.client.Client
的用法示例。
在下文中一共展示了Client.search方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doRequest
import org.elasticsearch.client.Client; //導入方法依賴的package包/類
@Override
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
CountRequest countRequest = new CountRequest(indices);
String source = request.param("source");
if (source != null) {
countRequest.source(source);
} else {
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
if (querySourceBuilder != null) {
countRequest.source(querySourceBuilder);
}
}
client.search(countRequest.toSearchRequest(), new RestResponseListener<SearchResponse>(channel) {
@Override
public RestResponse buildResponse(SearchResponse countResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, countResponse), channel);
}
});
}
示例2: handleRequest
import org.elasticsearch.client.Client; //導入方法依賴的package包/類
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
CountRequest countRequest = new CountRequest(Strings.splitStringByCommaToArray(request.param("index")));
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
if (RestActions.hasBodyContent(request)) {
countRequest.source(RestActions.getRestContent(request));
} else {
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
if (querySourceBuilder != null) {
countRequest.source(querySourceBuilder);
}
}
countRequest.routing(request.param("routing"));
countRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE));
countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
countRequest.preference(request.param("preference"));
final int terminateAfter = request.paramAsInt("terminate_after", DEFAULT_TERMINATE_AFTER);
if (terminateAfter < 0) {
throw new IllegalArgumentException("terminateAfter must be > 0");
} else if (terminateAfter > 0) {
countRequest.terminateAfter(terminateAfter);
}
client.search(countRequest.toSearchRequest(), new RestBuilderListener<SearchResponse>(channel) {
@Override
public RestResponse buildResponse(SearchResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
if (terminateAfter != DEFAULT_TERMINATE_AFTER) {
builder.field("terminated_early", response.isTerminatedEarly());
}
builder.field("count", response.getHits().totalHits());
buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(),
response.getFailedShards(), response.getShardFailures());
builder.endObject();
return new BytesRestResponse(response.status(), builder);
}
});
}
示例3: handleRequest
import org.elasticsearch.client.Client; //導入方法依賴的package包/類
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
SearchRequest searchRequest = new SearchRequest();
RestSearchAction.parseSearchRequest(searchRequest, request, parseFieldMatcher, null);
client.search(searchRequest, new RestStatusToXContentListener<SearchResponse>(channel));
}