Search in sources :

Example 1 with RemoteInfo

use of org.opensearch.index.reindex.RemoteInfo in project OpenSearch by opensearch-project.

the class RequestConvertersTests method testReindex.

public void testReindex() throws IOException {
    ReindexRequest reindexRequest = new ReindexRequest();
    reindexRequest.setSourceIndices("source_idx");
    reindexRequest.setDestIndex("dest_idx");
    Map<String, String> expectedParams = new HashMap<>();
    if (randomBoolean()) {
        XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint();
        RemoteInfo remoteInfo = new RemoteInfo("http", "remote-host", 9200, null, BytesReference.bytes(matchAllQuery().toXContent(builder, ToXContent.EMPTY_PARAMS)), "user", "pass", emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT);
        reindexRequest.setRemoteInfo(remoteInfo);
    }
    if (randomBoolean()) {
        reindexRequest.setSourceBatchSize(randomInt(100));
    }
    if (randomBoolean()) {
        reindexRequest.setDestOpType("create");
    }
    if (randomBoolean()) {
        reindexRequest.setDestPipeline("my_pipeline");
    }
    if (randomBoolean()) {
        float requestsPerSecond = (float) randomDoubleBetween(0.0, 10.0, false);
        expectedParams.put(RethrottleRequest.REQUEST_PER_SECOND_PARAMETER, Float.toString(requestsPerSecond));
        reindexRequest.setRequestsPerSecond(requestsPerSecond);
    } else {
        expectedParams.put(RethrottleRequest.REQUEST_PER_SECOND_PARAMETER, "-1");
    }
    if (randomBoolean()) {
        reindexRequest.setDestRouting("=cat");
    }
    if (randomBoolean()) {
        if (randomBoolean()) {
            reindexRequest.setMaxDocs(randomIntBetween(100, 1000));
        } else {
            reindexRequest.setSize(randomIntBetween(100, 1000));
        }
    }
    if (randomBoolean()) {
        reindexRequest.setAbortOnVersionConflict(false);
    }
    if (randomBoolean()) {
        String ts = randomTimeValue();
        reindexRequest.setScroll(TimeValue.parseTimeValue(ts, "scroll"));
    }
    if (reindexRequest.getRemoteInfo() == null && randomBoolean()) {
        reindexRequest.setSourceQuery(new TermQueryBuilder("foo", "fooval"));
    }
    if (randomBoolean()) {
        int slices = randomIntBetween(0, 4);
        reindexRequest.setSlices(slices);
        if (slices == 0) {
            expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
        } else {
            expectedParams.put("slices", Integer.toString(slices));
        }
    } else {
        expectedParams.put("slices", "1");
    }
    setRandomTimeout(reindexRequest::setTimeout, ReplicationRequest.DEFAULT_TIMEOUT, expectedParams);
    setRandomWaitForActiveShards(reindexRequest::setWaitForActiveShards, ActiveShardCount.DEFAULT, expectedParams);
    expectedParams.put("scroll", reindexRequest.getScrollTime().getStringRep());
    expectedParams.put("wait_for_completion", Boolean.TRUE.toString());
    Request request = RequestConverters.reindex(reindexRequest);
    assertEquals("/_reindex", request.getEndpoint());
    assertEquals(HttpPost.METHOD_NAME, request.getMethod());
    assertEquals(expectedParams, request.getParameters());
    assertToXContentBody(reindexRequest, request.getEntity());
}
Also used : ReindexRequest(org.opensearch.index.reindex.ReindexRequest) 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) RemoteInfo(org.opensearch.index.reindex.RemoteInfo) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

HashMap (java.util.HashMap)1 DocWriteRequest (org.opensearch.action.DocWriteRequest)1 DeleteStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest)1 GetStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest)1 PutStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)1 BulkRequest (org.opensearch.action.bulk.BulkRequest)1 BulkShardRequest (org.opensearch.action.bulk.BulkShardRequest)1 DeleteRequest (org.opensearch.action.delete.DeleteRequest)1 ExplainRequest (org.opensearch.action.explain.ExplainRequest)1 FieldCapabilitiesRequest (org.opensearch.action.fieldcaps.FieldCapabilitiesRequest)1 GetRequest (org.opensearch.action.get.GetRequest)1 MultiGetRequest (org.opensearch.action.get.MultiGetRequest)1 IndexRequest (org.opensearch.action.index.IndexRequest)1 ClearScrollRequest (org.opensearch.action.search.ClearScrollRequest)1 MultiSearchRequest (org.opensearch.action.search.MultiSearchRequest)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 SearchScrollRequest (org.opensearch.action.search.SearchScrollRequest)1 WriteRequest (org.opensearch.action.support.WriteRequest)1 AcknowledgedRequest (org.opensearch.action.support.master.AcknowledgedRequest)1 MasterNodeRequest (org.opensearch.action.support.master.MasterNodeRequest)1