Search in sources :

Example 1 with IndicesOptions

use of org.opensearch.action.support.IndicesOptions in project OpenSearch by opensearch-project.

the class RequestConvertersTests method testMultiSearch.

public void testMultiSearch() throws IOException {
    int numberOfSearchRequests = randomIntBetween(0, 32);
    MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
    for (int i = 0; i < numberOfSearchRequests; i++) {
        SearchRequest searchRequest = randomSearchRequest(() -> {
            // No need to return a very complex SearchSourceBuilder here, that is tested
            // elsewhere
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.from(randomInt(10));
            searchSourceBuilder.size(randomIntBetween(20, 100));
            return searchSourceBuilder;
        });
        // scroll is not supported in the current msearch api, so unset it:
        searchRequest.scroll((Scroll) null);
        // only expand_wildcards, ignore_unavailable and allow_no_indices can be
        // specified from msearch api, so unset other options:
        IndicesOptions randomlyGenerated = searchRequest.indicesOptions();
        IndicesOptions msearchDefault = new MultiSearchRequest().indicesOptions();
        searchRequest.indicesOptions(IndicesOptions.fromOptions(randomlyGenerated.ignoreUnavailable(), randomlyGenerated.allowNoIndices(), randomlyGenerated.expandWildcardsOpen(), randomlyGenerated.expandWildcardsClosed(), msearchDefault.expandWildcardsHidden(), msearchDefault.allowAliasesToMultipleIndices(), msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases(), msearchDefault.ignoreThrottled()));
        multiSearchRequest.add(searchRequest);
    }
    Map<String, String> expectedParams = new HashMap<>();
    expectedParams.put(RestSearchAction.TYPED_KEYS_PARAM, "true");
    if (randomBoolean()) {
        multiSearchRequest.maxConcurrentSearchRequests(randomIntBetween(1, 8));
        expectedParams.put("max_concurrent_searches", Integer.toString(multiSearchRequest.maxConcurrentSearchRequests()));
    }
    Request request = RequestConverters.multiSearch(multiSearchRequest);
    assertEquals("/_msearch", request.getEndpoint());
    assertEquals(HttpPost.METHOD_NAME, request.getMethod());
    assertEquals(expectedParams, request.getParameters());
    List<SearchRequest> requests = new ArrayList<>();
    CheckedBiConsumer<SearchRequest, XContentParser, IOException> consumer = (searchRequest, p) -> {
        SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(p, false);
        if (searchSourceBuilder.equals(new SearchSourceBuilder()) == false) {
            searchRequest.source(searchSourceBuilder);
        }
        requests.add(searchRequest);
    };
    MultiSearchRequest.readMultiLineFormat(new BytesArray(EntityUtils.toByteArray(request.getEntity())), REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null, null, xContentRegistry(), true, deprecationLogger);
    assertEquals(requests, multiSearchRequest.requests());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Arrays(java.util.Arrays) NByteArrayEntity(org.apache.http.nio.entity.NByteArrayEntity) Strings(org.opensearch.common.Strings) ScriptType(org.opensearch.script.ScriptType) 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) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) DeleteRequest(org.opensearch.action.delete.DeleteRequest) ValueType(org.opensearch.search.aggregations.support.ValueType) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) TimeValue(org.opensearch.common.unit.TimeValue) PrecisionAtK(org.opensearch.index.rankeval.PrecisionAtK) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) VersionType(org.opensearch.index.VersionType) SuggestBuilder(org.opensearch.search.suggest.SuggestBuilder) BytesArray(org.opensearch.common.bytes.BytesArray) CollapseBuilder(org.opensearch.search.collapse.CollapseBuilder) UpdateRequest(org.opensearch.action.update.UpdateRequest) XContentType(org.opensearch.common.xcontent.XContentType) OpenSearchAssertions.assertToXContentEquivalent(org.opensearch.test.hamcrest.OpenSearchAssertions.assertToXContentEquivalent) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) HttpHead(org.apache.http.client.methods.HttpHead) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) DocWriteRequest(org.opensearch.action.DocWriteRequest) RemoteInfo(org.opensearch.index.reindex.RemoteInfo) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) RestSearchAction(org.opensearch.rest.action.search.RestSearchAction) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) Streams(org.opensearch.common.io.Streams) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) QueryBuilders(org.opensearch.index.query.QueryBuilders) Versions(org.opensearch.common.lucene.uid.Versions) QueryRescorerBuilder(org.opensearch.search.rescore.QueryRescorerBuilder) SearchType(org.opensearch.action.search.SearchType) TaskId(org.opensearch.tasks.TaskId) IOException(java.io.IOException) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentHelper(org.opensearch.common.xcontent.XContentHelper) RankEvalSpec(org.opensearch.index.rankeval.RankEvalSpec) EndpointBuilder(org.opensearch.client.RequestConverters.EndpointBuilder) RestRankEvalAction(org.opensearch.index.rankeval.RestRankEvalAction) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) RequestConverters.enforceSameContentType(org.opensearch.client.RequestConverters.enforceSameContentType) CompletionSuggestionBuilder(org.opensearch.search.suggest.completion.CompletionSuggestionBuilder) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) ToXContent(org.opensearch.common.xcontent.ToXContent) BiFunction(java.util.function.BiFunction) BulkRequest(org.opensearch.action.bulk.BulkRequest) Matchers.hasKey(org.hamcrest.Matchers.hasKey) EntityUtils(org.apache.http.util.EntityUtils) XContentParser(org.opensearch.common.xcontent.XContentParser) MapperService(org.opensearch.index.mapper.MapperService) QueryBuilders.matchAllQuery(org.opensearch.index.query.QueryBuilders.matchAllQuery) Locale(java.util.Locale) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) ReplicationRequest(org.opensearch.action.support.replication.ReplicationRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) Scroll(org.opensearch.search.Scroll) RandomObjects(org.opensearch.test.RandomObjects) CountRequest(org.opensearch.client.core.CountRequest) BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) Script(org.opensearch.script.Script) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) HttpEntity(org.apache.http.HttpEntity) Tuple(org.opensearch.common.collect.Tuple) List(java.util.List) HttpGet(org.apache.http.client.methods.HttpGet) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) BytesReference(org.opensearch.common.bytes.BytesReference) CheckedBiConsumer(org.opensearch.common.CheckedBiConsumer) HighlightBuilder(org.opensearch.search.fetch.subphase.highlight.HighlightBuilder) HashMap(java.util.HashMap) IndicesOptions(org.opensearch.action.support.IndicesOptions) Function(java.util.function.Function) REQUEST_BODY_CONTENT_TYPE(org.opensearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) HashSet(java.util.HashSet) HttpDelete(org.apache.http.client.methods.HttpDelete) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) Collections.emptyMap(java.util.Collections.emptyMap) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) Matchers(org.hamcrest.Matchers) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) Consumer(java.util.function.Consumer) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) HttpPut(org.apache.http.client.methods.HttpPut) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) TermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) StringJoiner(java.util.StringJoiner) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) IndexRequest(org.opensearch.action.index.IndexRequest) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder) ReindexRequest(org.opensearch.index.reindex.ReindexRequest) Collections(java.util.Collections) FetchSourceContext(org.opensearch.search.fetch.subphase.FetchSourceContext) InputStream(java.io.InputStream) RandomSearchRequestGenerator.randomSearchRequest(org.opensearch.search.RandomSearchRequestGenerator.randomSearchRequest) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) SearchRequest(org.opensearch.action.search.SearchRequest) BytesArray(org.opensearch.common.bytes.BytesArray) 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) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) IndicesOptions(org.opensearch.action.support.IndicesOptions) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 2 with IndicesOptions

use of org.opensearch.action.support.IndicesOptions in project OpenSearch by opensearch-project.

the class CloseIndexRequestTests method testIndicesOptions.

public void testIndicesOptions() {
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
    CloseIndexRequest request = new CloseIndexRequest().indicesOptions(indicesOptions);
    assertEquals(indicesOptions, request.indicesOptions());
}
Also used : IndicesOptions(org.opensearch.action.support.IndicesOptions)

Example 3 with IndicesOptions

use of org.opensearch.action.support.IndicesOptions in project OpenSearch by opensearch-project.

the class RankEvalRequestTests method createTestInstance.

@Override
protected RankEvalRequest createTestInstance() {
    int numberOfIndices = randomInt(3);
    String[] indices = new String[numberOfIndices];
    for (int i = 0; i < numberOfIndices; i++) {
        indices[i] = randomAlphaOfLengthBetween(5, 10);
    }
    RankEvalRequest rankEvalRequest = new RankEvalRequest(RankEvalSpecTests.createTestItem(), indices);
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
    rankEvalRequest.indicesOptions(indicesOptions);
    rankEvalRequest.searchType(randomFrom(SearchType.DFS_QUERY_THEN_FETCH, SearchType.QUERY_THEN_FETCH));
    return rankEvalRequest;
}
Also used : IndicesOptions(org.opensearch.action.support.IndicesOptions)

Example 4 with IndicesOptions

use of org.opensearch.action.support.IndicesOptions in project OpenSearch by opensearch-project.

the class SimpleClusterStateIT method testIndicesOptionsOnAllowNoIndicesFalse.

public void testIndicesOptionsOnAllowNoIndicesFalse() throws Exception {
    // empty wildcard expansion throws exception when allowNoIndices is turned off
    IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, false, true, false);
    try {
        client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("a*").setIndicesOptions(allowNoIndices).get();
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), is("no such index [a*]"));
    }
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException) IndicesOptions(org.opensearch.action.support.IndicesOptions)

Example 5 with IndicesOptions

use of org.opensearch.action.support.IndicesOptions in project OpenSearch by opensearch-project.

the class SimpleClusterStateIT method testIndicesIgnoreUnavailableFalse.

public void testIndicesIgnoreUnavailableFalse() throws Exception {
    // ignore_unavailable set to false throws exception when allowNoIndices is turned off
    IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false);
    try {
        client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("fzzbzz").setIndicesOptions(allowNoIndices).get();
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), is("no such index [fzzbzz]"));
    }
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException) IndicesOptions(org.opensearch.action.support.IndicesOptions)

Aggregations

IndicesOptions (org.opensearch.action.support.IndicesOptions)64 ClusterName (org.opensearch.cluster.ClusterName)21 ClusterState (org.opensearch.cluster.ClusterState)21 Matchers.containsString (org.hamcrest.Matchers.containsString)19 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)13 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)11 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Index (org.opensearch.index.Index)8 DataStreamTestHelper.createBackingIndex (org.opensearch.cluster.DataStreamTestHelper.createBackingIndex)6 Strings (org.opensearch.common.Strings)6 NodeClient (org.opensearch.client.node.NodeClient)5 IOException (java.io.IOException)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 SearchRequest (org.opensearch.action.search.SearchRequest)4 TimeValue (org.opensearch.common.unit.TimeValue)4