Search in sources :

Example 61 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndicesOptionsIntegrationIT method verify.

private static void verify(ActionRequestBuilder requestBuilder, boolean fail, long expectedCount) {
    if (fail) {
        if (requestBuilder instanceof MultiSearchRequestBuilder) {
            MultiSearchResponse multiSearchResponse = ((MultiSearchRequestBuilder) requestBuilder).get();
            assertThat(multiSearchResponse.getResponses().length, equalTo(1));
            assertThat(multiSearchResponse.getResponses()[0].isFailure(), is(true));
            assertThat(multiSearchResponse.getResponses()[0].getResponse(), nullValue());
        } else {
            try {
                requestBuilder.get();
                fail("IndexNotFoundException or IndexClosedException was expected");
            } catch (IndexNotFoundException | IndexClosedException e) {
            }
        }
    } else {
        if (requestBuilder instanceof SearchRequestBuilder) {
            SearchRequestBuilder searchRequestBuilder = (SearchRequestBuilder) requestBuilder;
            assertHitCount(searchRequestBuilder.get(), expectedCount);
        } else if (requestBuilder instanceof MultiSearchRequestBuilder) {
            MultiSearchResponse multiSearchResponse = ((MultiSearchRequestBuilder) requestBuilder).get();
            assertThat(multiSearchResponse.getResponses().length, equalTo(1));
            assertThat(multiSearchResponse.getResponses()[0].getResponse(), notNullValue());
        } else {
            requestBuilder.get();
        }
    }
}
Also used : MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequestBuilder(org.elasticsearch.action.search.MultiSearchRequestBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) MultiSearchRequestBuilder(org.elasticsearch.action.search.MultiSearchRequestBuilder)

Example 62 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsSingleIndexNoExpandWildcards.

public void testIndexOptionsSingleIndexNoExpandWildcards() {
    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();
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("baz*"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("baz*"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foo", "foofoobar");
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foofoo-closed", "foofoobar");
        fail();
    } catch (IndexClosedException e) {
        assertThat(e.getMessage(), equalTo("closed"));
        assertEquals(e.getIndex().getName(), "foofoo-closed");
    }
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "barbaz");
    assertEquals(2, results.length);
    assertThat(results, arrayContainingInAnyOrder("foo", "foofoo"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexClosedException(org.elasticsearch.indices.IndexClosedException) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 63 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsStrict.

public void testIndexOptionsStrict() {
    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();
    IndicesOptions[] indicesOptions = new IndicesOptions[] { IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand() };
    for (IndicesOptions options : indicesOptions) {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "bar");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("bar"));
        }
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo", "foobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar"));
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(new HashSet<>(Arrays.asList("foo", "foobar")), new HashSet<>(Arrays.asList(results)));
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "bar");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("bar"));
        }
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "foo", "bar");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("bar"));
        }
        results = indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "foobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar"));
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "bar");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("bar"));
        }
        results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        assertThat(results, emptyArray());
        results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
    }
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertEquals(3, results.length);
    results = indexNameExpressionResolver.concreteIndexNames(context, (String[]) null);
    assertEquals(3, results.length);
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand());
    results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertEquals(4, results.length);
    results = indexNameExpressionResolver.concreteIndexNames(context, (String[]) null);
    assertEquals(4, results.length);
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*");
    assertEquals(3, results.length);
    assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo"));
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*");
    assertEquals(4, results.length);
    assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 64 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsAllowUnavailableDisallowEmpty.

public void testIndexOptionsAllowUnavailableDisallowEmpty() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("foo")).put(indexBuilder("foobar")).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();
    IndicesOptions expandOpen = IndicesOptions.fromOptions(true, false, true, false);
    IndicesOptions expand = IndicesOptions.fromOptions(true, false, true, true);
    IndicesOptions[] indicesOptions = new IndicesOptions[] { expandOpen, expand };
    for (IndicesOptions options : indicesOptions) {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "bar");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("bar"));
        }
        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*"));
        }
    }
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, expandOpen);
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertEquals(3, results.length);
    context = new IndexNameExpressionResolver.Context(state, expand);
    results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertEquals(4, results.length);
}
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 65 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testConcreteIndicesIgnoreIndicesOneMissingIndex.

public void testConcreteIndicesIgnoreIndicesOneMissingIndex() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("testXXX")).put(indexBuilder("kuku"));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "testZZZ");
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), is("no such index"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Aggregations

IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)92 ClusterState (org.elasticsearch.cluster.ClusterState)22 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)21 ShardId (org.elasticsearch.index.shard.ShardId)19 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)16 Index (org.elasticsearch.index.Index)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)12 List (java.util.List)11 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)11 ClusterName (org.elasticsearch.cluster.ClusterName)9 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)9 Settings (org.elasticsearch.common.settings.Settings)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 HashMap (java.util.HashMap)8 Nullable (javax.annotation.Nullable)8 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)8 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)8