use of org.opensearch.action.get.MultiGetRequest in project OpenSearch by opensearch-project.
the class SearchIdleIT method testAutomaticRefreshMultiGet.
public void testAutomaticRefreshMultiGet() throws InterruptedException {
runTestAutomaticRefresh(numDocs -> {
final MultiGetRequest request = new MultiGetRequest();
request.realtime(false);
for (int i = 0; i < numDocs; i++) {
request.add("test", "" + i);
}
return Arrays.stream(client().multiGet(request).actionGet().getResponses()).filter(r -> r.getResponse().isExists()).count();
});
}
use of org.opensearch.action.get.MultiGetRequest in project OpenSearch by opensearch-project.
the class RestMultiGetAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
multiGetRequest.preference(request.param("preference"));
multiGetRequest.realtime(request.paramAsBoolean("realtime", multiGetRequest.realtime()));
if (request.param("fields") != null) {
throw new IllegalArgumentException("The parameter [fields] is no longer supported, " + "please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored");
}
String[] sFields = null;
String sField = request.param("stored_fields");
if (sField != null) {
sFields = Strings.splitStringByCommaToArray(sField);
}
FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
try (XContentParser parser = request.contentOrSourceParamParser()) {
multiGetRequest.add(request.param("index"), sFields, defaultFetchSource, request.param("routing"), parser, allowExplicitIndex);
}
return channel -> client.multiGet(multiGetRequest, new RestToXContentListener<>(channel));
}
Aggregations