Search in sources :

Example 26 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsNoExpandWildcards.

public void testIndexOptionsNoExpandWildcards() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("foo").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foobar").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foofoo-closed").state(IndexMetaData.State.CLOSE)).put(indexBuilder("foofoo").putAlias(AliasMetaData.builder("barbaz")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    //ignore unavailable and allow no indices
    {
        IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        assertThat(results, emptyArray());
        results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
        results = indexNameExpressionResolver.concreteIndexNames(context, (String[]) null);
        assertEquals(0, results.length);
        results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
        assertEquals(0, results.length);
    }
    //ignore unavailable but don't allow no indices
    {
        IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
    //error on unavailable but allow no indices
    {
        IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        assertThat(results, emptyArray());
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
    //error on both unavailable and no indices
    {
        IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 27 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsEmptyCluster.

public void testIndexOptionsEmptyCluster() {
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(MetaData.builder().build()).build();
    IndicesOptions options = IndicesOptions.strictExpandOpen();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertThat(results, emptyArray());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foo");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("foo"));
    }
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertThat(results, emptyArray());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("bar"));
    }
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
    results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
    assertThat(results, emptyArray());
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false));
    try {
        indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    } catch (IndexNotFoundException e) {
        assertThat(e.getResourceId().toString(), equalTo("[_all]"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 28 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class IndicesOptionsIntegrationIT method testSpecifiedIndexUnavailableMultipleIndices.

public void testSpecifiedIndexUnavailableMultipleIndices() throws Exception {
    assertAcked(prepareCreate("test1"));
    // Verify defaults
    verify(search("test1", "test2"), true);
    verify(msearch(null, "test1", "test2"), true);
    verify(clearCache("test1", "test2"), true);
    verify(_flush("test1", "test2"), true);
    verify(segments("test1", "test2"), true);
    verify(stats("test1", "test2"), true);
    verify(forceMerge("test1", "test2"), true);
    verify(refreshBuilder("test1", "test2"), true);
    verify(validateQuery("test1", "test2"), true);
    verify(aliasExists("test1", "test2"), true);
    verify(typesExists("test1", "test2"), true);
    verify(getAliases("test1", "test2"), true);
    verify(getFieldMapping("test1", "test2"), true);
    verify(getMapping("test1", "test2"), true);
    verify(getSettings("test1", "test2"), true);
    IndicesOptions options = IndicesOptions.strictExpandOpen();
    verify(search("test1", "test2").setIndicesOptions(options), true);
    verify(msearch(options, "test1", "test2"), true);
    verify(clearCache("test1", "test2").setIndicesOptions(options), true);
    verify(_flush("test1", "test2").setIndicesOptions(options), true);
    verify(segments("test1", "test2").setIndicesOptions(options), true);
    verify(stats("test1", "test2").setIndicesOptions(options), true);
    verify(forceMerge("test1", "test2").setIndicesOptions(options), true);
    verify(refreshBuilder("test1", "test2").setIndicesOptions(options), true);
    verify(validateQuery("test1", "test2").setIndicesOptions(options), true);
    verify(aliasExists("test1", "test2").setIndicesOptions(options), true);
    verify(typesExists("test1", "test2").setIndicesOptions(options), true);
    verify(getAliases("test1", "test2").setIndicesOptions(options), true);
    verify(getFieldMapping("test1", "test2").setIndicesOptions(options), true);
    verify(getMapping("test1", "test2").setIndicesOptions(options), true);
    verify(getSettings("test1", "test2").setIndicesOptions(options), true);
    options = IndicesOptions.lenientExpandOpen();
    verify(search("test1", "test2").setIndicesOptions(options), false);
    verify(msearch(options, "test1", "test2").setIndicesOptions(options), false);
    verify(clearCache("test1", "test2").setIndicesOptions(options), false);
    verify(_flush("test1", "test2").setIndicesOptions(options), false);
    verify(segments("test1", "test2").setIndicesOptions(options), false);
    verify(stats("test1", "test2").setIndicesOptions(options), false);
    verify(forceMerge("test1", "test2").setIndicesOptions(options), false);
    verify(refreshBuilder("test1", "test2").setIndicesOptions(options), false);
    verify(validateQuery("test1", "test2").setIndicesOptions(options), false);
    verify(aliasExists("test1", "test2").setIndicesOptions(options), false);
    verify(typesExists("test1", "test2").setIndicesOptions(options), false);
    verify(getAliases("test1", "test2").setIndicesOptions(options), false);
    verify(getFieldMapping("test1", "test2").setIndicesOptions(options), false);
    verify(getMapping("test1", "test2").setIndicesOptions(options), false);
    verify(getSettings("test1", "test2").setIndicesOptions(options), false);
    options = IndicesOptions.strictExpandOpen();
    assertAcked(prepareCreate("test2"));
    verify(search("test1", "test2").setIndicesOptions(options), false);
    verify(msearch(options, "test1", "test2").setIndicesOptions(options), false);
    verify(clearCache("test1", "test2").setIndicesOptions(options), false);
    verify(_flush("test1", "test2").setIndicesOptions(options), false);
    verify(segments("test1", "test2").setIndicesOptions(options), false);
    verify(stats("test1", "test2").setIndicesOptions(options), false);
    verify(forceMerge("test1", "test2").setIndicesOptions(options), false);
    verify(refreshBuilder("test1", "test2").setIndicesOptions(options), false);
    verify(validateQuery("test1", "test2").setIndicesOptions(options), false);
    verify(aliasExists("test1", "test2").setIndicesOptions(options), false);
    verify(typesExists("test1", "test2").setIndicesOptions(options), false);
    verify(getAliases("test1", "test2").setIndicesOptions(options), false);
    verify(getFieldMapping("test1", "test2").setIndicesOptions(options), false);
    verify(getMapping("test1", "test2").setIndicesOptions(options), false);
    verify(getSettings("test1", "test2").setIndicesOptions(options), false);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 29 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class IndicesOptionsIntegrationIT method testSpecifiedIndexUnavailableSingleIndex.

public void testSpecifiedIndexUnavailableSingleIndex() throws Exception {
    IndicesOptions options = IndicesOptions.strictExpandOpenAndForbidClosed();
    verify(search("test1").setIndicesOptions(options), true);
    verify(msearch(options, "test1"), true);
    verify(clearCache("test1").setIndicesOptions(options), true);
    verify(_flush("test1").setIndicesOptions(options), true);
    verify(segments("test1").setIndicesOptions(options), true);
    verify(stats("test1").setIndicesOptions(options), true);
    verify(forceMerge("test1").setIndicesOptions(options), true);
    verify(refreshBuilder("test1").setIndicesOptions(options), true);
    verify(validateQuery("test1").setIndicesOptions(options), true);
    verify(aliasExists("test1").setIndicesOptions(options), true);
    verify(typesExists("test1").setIndicesOptions(options), true);
    verify(getAliases("test1").setIndicesOptions(options), true);
    verify(getFieldMapping("test1").setIndicesOptions(options), true);
    verify(getMapping("test1").setIndicesOptions(options), true);
    verify(getSettings("test1").setIndicesOptions(options), true);
    options = IndicesOptions.fromOptions(true, options.allowNoIndices(), options.expandWildcardsOpen(), options.expandWildcardsClosed(), options);
    verify(search("test1").setIndicesOptions(options), false);
    verify(msearch(options, "test1"), false);
    verify(clearCache("test1").setIndicesOptions(options), false);
    verify(_flush("test1").setIndicesOptions(options), false);
    verify(segments("test1").setIndicesOptions(options), false);
    verify(stats("test1").setIndicesOptions(options), false);
    verify(forceMerge("test1").setIndicesOptions(options), false);
    verify(refreshBuilder("test1").setIndicesOptions(options), false);
    verify(validateQuery("test1").setIndicesOptions(options), false);
    verify(aliasExists("test1").setIndicesOptions(options), false);
    verify(typesExists("test1").setIndicesOptions(options), false);
    verify(getAliases("test1").setIndicesOptions(options), false);
    verify(getFieldMapping("test1").setIndicesOptions(options), false);
    verify(getMapping("test1").setIndicesOptions(options), false);
    verify(getSettings("test1").setIndicesOptions(options), false);
    assertAcked(prepareCreate("test1"));
    options = IndicesOptions.strictExpandOpenAndForbidClosed();
    verify(search("test1").setIndicesOptions(options), false);
    verify(msearch(options, "test1"), false);
    verify(clearCache("test1").setIndicesOptions(options), false);
    verify(_flush("test1").setIndicesOptions(options), false);
    verify(segments("test1").setIndicesOptions(options), false);
    verify(stats("test1").setIndicesOptions(options), false);
    verify(forceMerge("test1").setIndicesOptions(options), false);
    verify(refreshBuilder("test1").setIndicesOptions(options), false);
    verify(validateQuery("test1").setIndicesOptions(options), false);
    verify(aliasExists("test1").setIndicesOptions(options), false);
    verify(typesExists("test1").setIndicesOptions(options), false);
    verify(getAliases("test1").setIndicesOptions(options), false);
    verify(getFieldMapping("test1").setIndicesOptions(options), false);
    verify(getMapping("test1").setIndicesOptions(options), false);
    verify(getSettings("test1").setIndicesOptions(options), false);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 30 with IndicesOptions

use of org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.

the class IndicesOptionsIntegrationIT method testSpecifiedIndexUnavailableSingleIndexThatIsClosed.

public void testSpecifiedIndexUnavailableSingleIndexThatIsClosed() throws Exception {
    assertAcked(prepareCreate("test1"));
    // we need to wait until all shards are allocated since recovery from
    // gateway will fail unless the majority of the replicas was allocated
    // pre-closing. with lots of replicas this will fail.
    ensureGreen();
    assertAcked(client().admin().indices().prepareClose("test1"));
    IndicesOptions options = IndicesOptions.strictExpandOpenAndForbidClosed();
    verify(search("test1").setIndicesOptions(options), true);
    verify(msearch(options, "test1"), true);
    verify(clearCache("test1").setIndicesOptions(options), true);
    verify(_flush("test1").setIndicesOptions(options), true);
    verify(segments("test1").setIndicesOptions(options), true);
    verify(stats("test1").setIndicesOptions(options), true);
    verify(forceMerge("test1").setIndicesOptions(options), true);
    verify(refreshBuilder("test1").setIndicesOptions(options), true);
    verify(validateQuery("test1").setIndicesOptions(options), true);
    verify(aliasExists("test1").setIndicesOptions(options), true);
    verify(typesExists("test1").setIndicesOptions(options), true);
    verify(getAliases("test1").setIndicesOptions(options), true);
    verify(getFieldMapping("test1").setIndicesOptions(options), true);
    verify(getMapping("test1").setIndicesOptions(options), true);
    verify(getSettings("test1").setIndicesOptions(options), true);
    options = IndicesOptions.fromOptions(true, options.allowNoIndices(), options.expandWildcardsOpen(), options.expandWildcardsClosed(), options);
    verify(search("test1").setIndicesOptions(options), false);
    verify(msearch(options, "test1"), false);
    verify(clearCache("test1").setIndicesOptions(options), false);
    verify(_flush("test1").setIndicesOptions(options), false);
    verify(segments("test1").setIndicesOptions(options), false);
    verify(stats("test1").setIndicesOptions(options), false);
    verify(forceMerge("test1").setIndicesOptions(options), false);
    verify(refreshBuilder("test1").setIndicesOptions(options), false);
    verify(validateQuery("test1").setIndicesOptions(options), false);
    verify(aliasExists("test1").setIndicesOptions(options), false);
    verify(typesExists("test1").setIndicesOptions(options), false);
    verify(getAliases("test1").setIndicesOptions(options), false);
    verify(getFieldMapping("test1").setIndicesOptions(options), false);
    verify(getMapping("test1").setIndicesOptions(options), false);
    verify(getSettings("test1").setIndicesOptions(options), false);
    assertAcked(client().admin().indices().prepareOpen("test1"));
    ensureYellow();
    options = IndicesOptions.strictExpandOpenAndForbidClosed();
    verify(search("test1").setIndicesOptions(options), false);
    verify(msearch(options, "test1"), false);
    verify(clearCache("test1").setIndicesOptions(options), false);
    verify(_flush("test1").setIndicesOptions(options), false);
    verify(segments("test1").setIndicesOptions(options), false);
    verify(stats("test1").setIndicesOptions(options), false);
    verify(forceMerge("test1").setIndicesOptions(options), false);
    verify(refreshBuilder("test1").setIndicesOptions(options), false);
    verify(validateQuery("test1").setIndicesOptions(options), false);
    verify(aliasExists("test1").setIndicesOptions(options), false);
    verify(typesExists("test1").setIndicesOptions(options), false);
    verify(getAliases("test1").setIndicesOptions(options), false);
    verify(getFieldMapping("test1").setIndicesOptions(options), false);
    verify(getMapping("test1").setIndicesOptions(options), false);
    verify(getSettings("test1").setIndicesOptions(options), false);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Aggregations

IndicesOptions (org.elasticsearch.action.support.IndicesOptions)33 ClusterState (org.elasticsearch.cluster.ClusterState)10 ClusterName (org.elasticsearch.cluster.ClusterName)9 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 NodeClient (org.elasticsearch.client.node.NodeClient)3 Strings (org.elasticsearch.common.Strings)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 Settings (org.elasticsearch.common.settings.Settings)3 RestController (org.elasticsearch.rest.RestController)3 RestRequest (org.elasticsearch.rest.RestRequest)3 GET (org.elasticsearch.rest.RestRequest.Method.GET)3 RestResponse (org.elasticsearch.rest.RestResponse)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 TestUtil.randomSimpleString (org.apache.lucene.util.TestUtil.randomSimpleString)2 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)2 CreateSnapshotRequest (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)2