Search in sources :

Example 1 with RefreshRequest

use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.

the class IndicesRequestConvertersTests method testRefresh.

public void testRefresh() {
    String[] indices = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
    RefreshRequest refreshRequest;
    if (OpenSearchTestCase.randomBoolean()) {
        refreshRequest = new RefreshRequest(indices);
    } else {
        refreshRequest = new RefreshRequest();
        refreshRequest.indices(indices);
    }
    Map<String, String> expectedParams = new HashMap<>();
    RequestConvertersTests.setRandomIndicesOptions(refreshRequest::indicesOptions, refreshRequest::indicesOptions, expectedParams);
    Request request = IndicesRequestConverters.refresh(refreshRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_refresh");
    Assert.assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
    Assert.assertThat(request.getParameters(), equalTo(expectedParams));
    Assert.assertThat(request.getEntity(), nullValue());
    Assert.assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}
Also used : RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) HashMap(java.util.HashMap) UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) StringJoiner(java.util.StringJoiner)

Example 2 with RefreshRequest

use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.

the class CCSDuelIT method indexDocuments.

private static void indexDocuments(String idPrefix) throws IOException, InterruptedException {
    // this index with a single document is used to test partial failures
    IndexRequest indexRequest = new IndexRequest(INDEX_NAME + "_err");
    indexRequest.id("id");
    indexRequest.source("id", "id", "creationDate", "err");
    indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
    IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    assertEquals(201, indexResponse.status().getStatus());
    CreateIndexRequest createEmptyIndexRequest = new CreateIndexRequest(INDEX_NAME + "_empty");
    CreateIndexResponse response = restHighLevelClient.indices().create(createEmptyIndexRequest, RequestOptions.DEFAULT);
    assertTrue(response.isAcknowledged());
    int numShards = randomIntBetween(1, 5);
    CreateIndexRequest createIndexRequest = new CreateIndexRequest(INDEX_NAME);
    createIndexRequest.settings(Settings.builder().put("index.number_of_shards", numShards).put("index.number_of_replicas", 0));
    createIndexRequest.mapping("{\"properties\":{" + "\"id\":{\"type\":\"keyword\"}," + "\"suggest\":{\"type\":\"completion\"}," + "\"join\":{\"type\":\"join\", \"relations\": {\"question\":\"answer\"}}}}", XContentType.JSON);
    CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
    assertTrue(createIndexResponse.isAcknowledged());
    BulkProcessor bulkProcessor = BulkProcessor.builder((r, l) -> restHighLevelClient.bulkAsync(r, RequestOptions.DEFAULT, l), new BulkProcessor.Listener() {

        @Override
        public void beforeBulk(long executionId, BulkRequest request) {
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
            assertFalse(response.hasFailures());
        }

        @Override
        public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
            throw new AssertionError("Failed to execute bulk", failure);
        }
    }).build();
    int numQuestions = randomIntBetween(50, 100);
    for (int i = 0; i < numQuestions; i++) {
        bulkProcessor.add(buildIndexRequest(idPrefix + i, "question", null));
    }
    int numAnswers = randomIntBetween(100, 150);
    for (int i = 0; i < numAnswers; i++) {
        bulkProcessor.add(buildIndexRequest(idPrefix + (i + 1000), "answer", idPrefix + randomIntBetween(0, numQuestions - 1)));
    }
    assertTrue(bulkProcessor.awaitClose(30, TimeUnit.SECONDS));
    RefreshResponse refreshResponse = restHighLevelClient.indices().refresh(new RefreshRequest(INDEX_NAME), RequestOptions.DEFAULT);
    assertEquals(0, refreshResponse.getFailedShards());
    assertEquals(numShards, refreshResponse.getSuccessfulShards());
}
Also used : Arrays(java.util.Arrays) Aggregation(org.opensearch.search.aggregations.Aggregation) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) IndexResponse(org.opensearch.action.index.IndexResponse) BulkRequest(org.opensearch.action.bulk.BulkRequest) Strings(org.opensearch.common.Strings) ScriptType(org.opensearch.script.ScriptType) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) WriteRequest(org.opensearch.action.support.WriteRequest) LatchedActionListener(org.opensearch.action.LatchedActionListener) Locale(java.util.Locale) BulkProcessor(org.opensearch.action.bulk.BulkProcessor) Map(java.util.Map) RestClient(org.opensearch.client.RestClient) TimeUnits(org.apache.lucene.util.TimeUnits) DirectCandidateGeneratorBuilder(org.opensearch.search.suggest.phrase.DirectCandidateGeneratorBuilder) ActionListener(org.opensearch.action.ActionListener) TermSuggestionBuilder(org.opensearch.search.suggest.term.TermSuggestionBuilder) FilterAggregationBuilder(org.opensearch.search.aggregations.bucket.filter.FilterAggregationBuilder) ValueType(org.opensearch.search.aggregations.support.ValueType) AfterClass(org.junit.AfterClass) RandomizedContext(com.carrotsearch.randomizedtesting.RandomizedContext) Script(org.opensearch.script.Script) NotEqualMessageBuilder(org.opensearch.test.NotEqualMessageBuilder) InnerHitBuilder(org.opensearch.index.query.InnerHitBuilder) DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) MultiBucketsAggregation(org.opensearch.search.aggregations.bucket.MultiBucketsAggregation) ScoreMode(org.apache.lucene.search.join.ScoreMode) PhraseSuggestion(org.opensearch.search.suggest.phrase.PhraseSuggestion) OpenSearchRestTestCase(org.opensearch.test.rest.OpenSearchRestTestCase) CountDownLatch(java.util.concurrent.CountDownLatch) TopHitsAggregationBuilder(org.opensearch.search.aggregations.metrics.TopHitsAggregationBuilder) List(java.util.List) CardinalityAggregationBuilder(org.opensearch.search.aggregations.metrics.CardinalityAggregationBuilder) SuggestBuilder(org.opensearch.search.suggest.SuggestBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) CollapseBuilder(org.opensearch.search.collapse.CollapseBuilder) LocalDate(java.time.LocalDate) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) TermsQueryBuilder(org.opensearch.index.query.TermsQueryBuilder) XContentType(org.opensearch.common.xcontent.XContentType) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) ScoreSortBuilder(org.opensearch.search.sort.ScoreSortBuilder) RequestOptions(org.opensearch.client.RequestOptions) TermSuggestion(org.opensearch.search.suggest.term.TermSuggestion) BucketOrder(org.opensearch.search.aggregations.BucketOrder) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) BytesReference(org.opensearch.common.bytes.BytesReference) TimeoutSuite(com.carrotsearch.randomizedtesting.annotations.TimeoutSuite) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) DateHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) MaxBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregationBuilder) HighlightBuilder(org.opensearch.search.fetch.subphase.highlight.HighlightBuilder) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) DateHistogramInterval(org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) SortOrder(org.opensearch.search.sort.SortOrder) HasChildQueryBuilder(org.opensearch.join.query.HasChildQueryBuilder) SearchRequest(org.opensearch.action.search.SearchRequest) SearchResponse(org.opensearch.action.search.SearchResponse) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) Before(org.junit.Before) QueryBuilders(org.opensearch.index.query.QueryBuilders) QueryRescorerBuilder(org.opensearch.search.rescore.QueryRescorerBuilder) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) RangeQueryBuilder(org.opensearch.index.query.RangeQueryBuilder) TermsLookup(org.opensearch.indices.TermsLookup) QueryRescoreMode(org.opensearch.search.rescore.QueryRescoreMode) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) IOException(java.io.IOException) XContentHelper(org.opensearch.common.xcontent.XContentHelper) IOUtils(org.opensearch.core.internal.io.IOUtils) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) PhraseSuggestionBuilder(org.opensearch.search.suggest.phrase.PhraseSuggestionBuilder) BulkResponse(org.opensearch.action.bulk.BulkResponse) TermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) HasParentQueryBuilder(org.opensearch.join.query.HasParentQueryBuilder) MatchQueryBuilder(org.opensearch.index.query.MatchQueryBuilder) IndexRequest(org.opensearch.action.index.IndexRequest) CompletionSuggestionBuilder(org.opensearch.search.suggest.completion.CompletionSuggestionBuilder) Collections(java.util.Collections) SumAggregationBuilder(org.opensearch.search.aggregations.metrics.SumAggregationBuilder) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) BulkResponse(org.opensearch.action.bulk.BulkResponse) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) IndexRequest(org.opensearch.action.index.IndexRequest) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) IndexResponse(org.opensearch.action.index.IndexResponse) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse) BulkProcessor(org.opensearch.action.bulk.BulkProcessor) BulkRequest(org.opensearch.action.bulk.BulkRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse)

Example 3 with RefreshRequest

use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.

the class AbstractAsyncBulkByScrollAction method refreshAndFinish.

/**
 * Start terminating a request that finished non-catastrophically by refreshing the modified indices and then proceeding to
 * {@link #finishHim(Exception, List, List, boolean)}.
 */
void refreshAndFinish(List<Failure> indexingFailures, List<SearchFailure> searchFailures, boolean timedOut) {
    if (task.isCancelled() || false == mainRequest.isRefresh() || destinationIndices.isEmpty()) {
        finishHim(null, indexingFailures, searchFailures, timedOut);
        return;
    }
    RefreshRequest refresh = new RefreshRequest();
    refresh.indices(destinationIndices.toArray(new String[destinationIndices.size()]));
    logger.debug("[{}]: refreshing", task.getId());
    client.admin().indices().refresh(refresh, new ActionListener<RefreshResponse>() {

        @Override
        public void onResponse(RefreshResponse response) {
            finishHim(null, indexingFailures, searchFailures, timedOut);
        }

        @Override
        public void onFailure(Exception e) {
            finishHim(e);
        }
    });
}
Also used : RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse)

Example 4 with RefreshRequest

use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.

the class RestRefreshAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));
    refreshRequest.indicesOptions(IndicesOptions.fromRequest(request, refreshRequest.indicesOptions()));
    return channel -> client.admin().indices().refresh(refreshRequest, new RestToXContentListener<RefreshResponse>(channel) {

        @Override
        protected RestStatus getStatus(RefreshResponse response) {
            return response.getStatus();
        }
    });
}
Also used : RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) 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) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) RestStatus(org.opensearch.rest.RestStatus) Strings(org.opensearch.common.Strings) List(java.util.List) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Arrays.asList(java.util.Arrays.asList) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) BaseRestHandler(org.opensearch.rest.BaseRestHandler) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) RestStatus(org.opensearch.rest.RestStatus)

Example 5 with RefreshRequest

use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.

the class IndicesRequestConverters method refresh.

static Request refresh(RefreshRequest refreshRequest) {
    String[] indices = refreshRequest.indices() == null ? Strings.EMPTY_ARRAY : refreshRequest.indices();
    Request request = new Request(HttpPost.METHOD_NAME, RequestConverters.endpoint(indices, "_refresh"));
    RequestConverters.Params parameters = new RequestConverters.Params();
    parameters.withIndicesOptions(refreshRequest.indicesOptions());
    request.addParameters(parameters.asMap());
    return request;
}
Also used : UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest)

Aggregations

RefreshRequest (org.opensearch.action.admin.indices.refresh.RefreshRequest)8 CountDownLatch (java.util.concurrent.CountDownLatch)3 RefreshResponse (org.opensearch.action.admin.indices.refresh.RefreshResponse)3 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 IndicesAliasesRequest (org.opensearch.action.admin.indices.alias.IndicesAliasesRequest)2 GetAliasesRequest (org.opensearch.action.admin.indices.alias.get.GetAliasesRequest)2 ClearIndicesCacheRequest (org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)2 DeleteIndexRequest (org.opensearch.action.admin.indices.delete.DeleteIndexRequest)2 FlushRequest (org.opensearch.action.admin.indices.flush.FlushRequest)2 Strings (org.opensearch.common.Strings)2 RemoteTransportException (org.opensearch.transport.RemoteTransportException)2 RandomizedContext (com.carrotsearch.randomizedtesting.RandomizedContext)1 TimeoutSuite (com.carrotsearch.randomizedtesting.annotations.TimeoutSuite)1 LocalDate (java.time.LocalDate)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1