Search in sources :

Example 1 with MultiGetRequest

use of org.opensearch.action.get.MultiGetRequest in project OpenSearch by opensearch-project.

the class BulkProcessorIT method testBulkProcessorWaitOnClose.

public void testBulkProcessorWaitOnClose() throws Exception {
    BulkProcessorTestListener listener = new BulkProcessorTestListener();
    int numDocs = randomIntBetween(10, 100);
    BulkProcessor processor = initBulkProcessorBuilder(listener).setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(randomIntBetween(1, 10), RandomPicks.randomFrom(random(), ByteSizeUnit.values()))).build();
    MultiGetRequest multiGetRequest = indexDocs(processor, numDocs);
    assertThat(processor.awaitClose(1, TimeUnit.MINUTES), is(true));
    if (randomBoolean()) {
        // check if we can call it multiple times
        if (randomBoolean()) {
            assertThat(processor.awaitClose(1, TimeUnit.MINUTES), is(true));
        } else {
            processor.close();
        }
    }
    assertThat(listener.beforeCounts.get(), greaterThanOrEqualTo(1));
    assertThat(listener.afterCounts.get(), greaterThanOrEqualTo(1));
    for (Throwable bulkFailure : listener.bulkFailures) {
        logger.error("bulk failure", bulkFailure);
    }
    assertThat(listener.bulkFailures.size(), equalTo(0));
    assertResponseItems(listener.bulkItems, numDocs);
    assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
}
Also used : BulkProcessor(org.opensearch.action.bulk.BulkProcessor) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 2 with MultiGetRequest

use of org.opensearch.action.get.MultiGetRequest in project OpenSearch by opensearch-project.

the class BulkProcessorIT method testThatBulkProcessorCountIsCorrect.

public void testThatBulkProcessorCountIsCorrect() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    BulkProcessorTestListener listener = new BulkProcessorTestListener(latch);
    int numDocs = randomIntBetween(10, 100);
    try (BulkProcessor processor = initBulkProcessorBuilder(listener).setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).build()) {
        MultiGetRequest multiGetRequest = indexDocs(processor, numDocs);
        latch.await();
        assertThat(listener.beforeCounts.get(), equalTo(1));
        assertThat(listener.afterCounts.get(), equalTo(1));
        assertThat(listener.bulkFailures.size(), equalTo(0));
        assertResponseItems(listener.bulkItems, numDocs);
        assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
    }
}
Also used : BulkProcessor(org.opensearch.action.bulk.BulkProcessor) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) CountDownLatch(java.util.concurrent.CountDownLatch) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 3 with MultiGetRequest

use of org.opensearch.action.get.MultiGetRequest in project OpenSearch by opensearch-project.

the class BulkProcessorIT method testBulkProcessorFlush.

public void testBulkProcessorFlush() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    BulkProcessorTestListener listener = new BulkProcessorTestListener(latch);
    int numDocs = randomIntBetween(10, 100);
    try (BulkProcessor processor = initBulkProcessorBuilder(listener).setConcurrentRequests(randomIntBetween(0, 10)).setBulkActions(numDocs + randomIntBetween(1, 100)).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).build()) {
        MultiGetRequest multiGetRequest = indexDocs(processor, numDocs);
        assertThat(latch.await(randomInt(500), TimeUnit.MILLISECONDS), equalTo(false));
        // we really need an explicit flush as none of the bulk thresholds was reached
        processor.flush();
        latch.await();
        assertThat(listener.beforeCounts.get(), equalTo(1));
        assertThat(listener.afterCounts.get(), equalTo(1));
        assertThat(listener.bulkFailures.size(), equalTo(0));
        assertResponseItems(listener.bulkItems, numDocs);
        assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
    }
}
Also used : BulkProcessor(org.opensearch.action.bulk.BulkProcessor) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) CountDownLatch(java.util.concurrent.CountDownLatch) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 4 with MultiGetRequest

use of org.opensearch.action.get.MultiGetRequest in project OpenSearch by opensearch-project.

the class BulkProcessorRetryIT method indexDocs.

private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) {
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    for (int i = 1; i <= numDocs; i++) {
        processor.add(new IndexRequest(INDEX_NAME).id(Integer.toString(i)).source(XContentType.JSON, "field", randomRealisticUnicodeOfCodepointLengthBetween(1, 30)));
        multiGetRequest.add(INDEX_NAME, Integer.toString(i));
    }
    return multiGetRequest;
}
Also used : IndexRequest(org.opensearch.action.index.IndexRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 5 with MultiGetRequest

use of org.opensearch.action.get.MultiGetRequest in project OpenSearch by opensearch-project.

the class RequestConvertersTests method testMultiGet.

public void testMultiGet() throws IOException {
    Map<String, String> expectedParams = new HashMap<>();
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    if (randomBoolean()) {
        String preference = randomAlphaOfLength(4);
        multiGetRequest.preference(preference);
        expectedParams.put("preference", preference);
    }
    if (randomBoolean()) {
        multiGetRequest.realtime(randomBoolean());
        if (multiGetRequest.realtime() == false) {
            expectedParams.put("realtime", "false");
        }
    }
    if (randomBoolean()) {
        multiGetRequest.refresh(randomBoolean());
        if (multiGetRequest.refresh()) {
            expectedParams.put("refresh", "true");
        }
    }
    int numberOfRequests = randomIntBetween(0, 32);
    for (int i = 0; i < numberOfRequests; i++) {
        MultiGetRequest.Item item = new MultiGetRequest.Item(randomAlphaOfLength(4), randomAlphaOfLength(4));
        if (randomBoolean()) {
            item.routing(randomAlphaOfLength(4));
        }
        if (randomBoolean()) {
            item.storedFields(generateRandomStringArray(16, 8, false));
        }
        if (randomBoolean()) {
            item.version(randomNonNegativeLong());
        }
        if (randomBoolean()) {
            item.versionType(randomFrom(VersionType.values()));
        }
        if (randomBoolean()) {
            randomizeFetchSourceContextParams(item::fetchSourceContext, new HashMap<>());
        }
        multiGetRequest.add(item);
    }
    Request request = RequestConverters.multiGet(multiGetRequest);
    assertEquals(HttpPost.METHOD_NAME, request.getMethod());
    assertEquals("/_mget", request.getEndpoint());
    assertEquals(expectedParams, request.getParameters());
    assertToXContentBody(multiGetRequest, request.getEntity());
}
Also used : HashMap(java.util.HashMap) RandomSearchRequestGenerator.randomSearchRequest(org.opensearch.search.RandomSearchRequestGenerator.randomSearchRequest) MasterNodeRequest(org.opensearch.action.support.master.MasterNodeRequest) WriteRequest(org.opensearch.action.support.WriteRequest) AbstractBulkByScrollRequest(org.opensearch.index.reindex.AbstractBulkByScrollRequest) RatedRequest(org.opensearch.index.rankeval.RatedRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) UpdateRequest(org.opensearch.action.update.UpdateRequest) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) DocWriteRequest(org.opensearch.action.DocWriteRequest) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) BulkRequest(org.opensearch.action.bulk.BulkRequest) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) ReplicationRequest(org.opensearch.action.support.replication.ReplicationRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) CountRequest(org.opensearch.client.core.CountRequest) BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) IndexRequest(org.opensearch.action.index.IndexRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest) 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