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"));
}
}
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]"));
}
}
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);
}
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);
}
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);
}
Aggregations