Search in sources :

Example 16 with MultiGetRequest

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();
    });
}
Also used : Arrays(java.util.Arrays) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchSingleNodeTestCase(org.opensearch.test.OpenSearchSingleNodeTestCase) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IndexResponse(org.opensearch.action.index.IndexResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) GetRequest(org.opensearch.action.get.GetRequest) Settings(org.opensearch.common.settings.Settings) IndexService(org.opensearch.index.IndexService) CountDownLatch(java.util.concurrent.CountDownLatch) IntToLongFunction(java.util.function.IntToLongFunction) OpenSearchAssertions.assertHitCount(org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Phaser(java.util.concurrent.Phaser) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IndexSettings(org.opensearch.index.IndexSettings) XContentType(org.opensearch.common.xcontent.XContentType) ActionListener(org.opensearch.action.ActionListener) OpenSearchAssertions.assertNoSearchHits(org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoSearchHits) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 17 with MultiGetRequest

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));
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) Strings(org.opensearch.common.Strings) XContentParser(org.opensearch.common.xcontent.XContentParser) List(java.util.List) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Arrays.asList(java.util.Arrays.asList) BaseRestHandler(org.opensearch.rest.BaseRestHandler) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) FetchSourceContext(org.opensearch.search.fetch.subphase.FetchSourceContext) FetchSourceContext(org.opensearch.search.fetch.subphase.FetchSourceContext) XContentParser(org.opensearch.common.xcontent.XContentParser) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Aggregations

MultiGetRequest (org.opensearch.action.get.MultiGetRequest)17 IndexRequest (org.opensearch.action.index.IndexRequest)9 BulkRequest (org.opensearch.action.bulk.BulkRequest)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 BulkProcessor (org.opensearch.action.bulk.BulkProcessor)6 GetRequest (org.opensearch.action.get.GetRequest)5 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)5 DocWriteRequest (org.opensearch.action.DocWriteRequest)4 BulkItemResponse (org.opensearch.action.bulk.BulkItemResponse)4 DeleteRequest (org.opensearch.action.delete.DeleteRequest)4 SearchRequest (org.opensearch.action.search.SearchRequest)4 WriteRequest (org.opensearch.action.support.WriteRequest)4 UpdateRequest (org.opensearch.action.update.UpdateRequest)4 GetSourceRequest (org.opensearch.client.core.GetSourceRequest)4 MultiTermVectorsRequest (org.opensearch.client.core.MultiTermVectorsRequest)4 TermVectorsRequest (org.opensearch.client.core.TermVectorsRequest)4 DeleteByQueryRequest (org.opensearch.index.reindex.DeleteByQueryRequest)4 ReindexRequest (org.opensearch.index.reindex.ReindexRequest)4 UpdateByQueryRequest (org.opensearch.index.reindex.UpdateByQueryRequest)4 DeleteStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest)3