use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.
the class IndexNameExpressionResolver method concreteIndices.
Index[] concreteIndices(Context context, String... indexExpressions) {
if (indexExpressions == null || indexExpressions.length == 0) {
indexExpressions = new String[] { MetaData.ALL };
}
MetaData metaData = context.getState().metaData();
IndicesOptions options = context.getOptions();
boolean failClosed = options.forbidClosedIndices() && options.ignoreUnavailable() == false;
boolean failNoIndices = options.ignoreUnavailable() == false;
// or multiple indices are specified yield different behaviour.
if (indexExpressions.length == 1) {
failNoIndices = options.allowNoIndices() == false;
}
List<String> expressions = Arrays.asList(indexExpressions);
for (ExpressionResolver expressionResolver : expressionResolvers) {
expressions = expressionResolver.resolve(context, expressions);
}
if (expressions.isEmpty()) {
if (!options.allowNoIndices()) {
IndexNotFoundException infe = new IndexNotFoundException((String) null);
infe.setResources("index_expression", indexExpressions);
throw infe;
} else {
return Index.EMPTY_ARRAY;
}
}
final Set<Index> concreteIndices = new HashSet<>(expressions.size());
for (String expression : expressions) {
AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression);
if (aliasOrIndex == null) {
if (failNoIndices) {
IndexNotFoundException infe = new IndexNotFoundException(expression);
infe.setResources("index_expression", expression);
throw infe;
} else {
continue;
}
}
Collection<IndexMetaData> resolvedIndices = aliasOrIndex.getIndices();
if (resolvedIndices.size() > 1 && !options.allowAliasesToMultipleIndices()) {
String[] indexNames = new String[resolvedIndices.size()];
int i = 0;
for (IndexMetaData indexMetaData : resolvedIndices) {
indexNames[i++] = indexMetaData.getIndex().getName();
}
throw new IllegalArgumentException("Alias [" + expression + "] has more than one indices associated with it [" + Arrays.toString(indexNames) + "], can't execute a single index op");
}
for (IndexMetaData index : resolvedIndices) {
if (index.getState() == IndexMetaData.State.CLOSE) {
if (failClosed) {
throw new IndexClosedException(index.getIndex());
} else {
if (options.forbidClosedIndices() == false) {
concreteIndices.add(index.getIndex());
}
}
} else if (index.getState() == IndexMetaData.State.OPEN) {
concreteIndices.add(index.getIndex());
} else {
throw new IllegalStateException("index state [" + index.getState() + "] not supported");
}
}
}
if (options.allowNoIndices() == false && concreteIndices.isEmpty()) {
IndexNotFoundException infe = new IndexNotFoundException((String) null);
infe.setResources("index_expression", indexExpressions);
throw infe;
}
return concreteIndices.toArray(new Index[concreteIndices.size()]);
}
use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project elasticsearch by elastic.
the class IndicesOptionsIntegrationIT method testWildcardBehaviour.
public void testWildcardBehaviour() throws Exception {
// Verify defaults for wildcards, when specifying no indices (*, _all, /)
String[] indices = Strings.EMPTY_ARRAY;
verify(search(indices), false);
verify(msearch(null, indices), false);
verify(clearCache(indices), false);
verify(_flush(indices), false);
verify(segments(indices), false);
verify(stats(indices), false);
verify(forceMerge(indices), false);
verify(refreshBuilder(indices), false);
verify(validateQuery(indices), true);
verify(aliasExists(indices), false);
verify(typesExists(indices), false);
verify(getAliases(indices), false);
verify(getFieldMapping(indices), false);
verify(getMapping(indices), false);
verify(getSettings(indices), false);
// Now force allow_no_indices=true
IndicesOptions options = IndicesOptions.fromOptions(false, true, true, false);
verify(search(indices).setIndicesOptions(options), false);
verify(msearch(options, indices).setIndicesOptions(options), false);
verify(clearCache(indices).setIndicesOptions(options), false);
verify(_flush(indices).setIndicesOptions(options), false);
verify(segments(indices).setIndicesOptions(options), false);
verify(stats(indices).setIndicesOptions(options), false);
verify(forceMerge(indices).setIndicesOptions(options), false);
verify(refreshBuilder(indices).setIndicesOptions(options), false);
verify(validateQuery(indices).setIndicesOptions(options), false);
verify(aliasExists(indices).setIndicesOptions(options), false);
verify(typesExists(indices).setIndicesOptions(options), false);
verify(getAliases(indices).setIndicesOptions(options), false);
verify(getFieldMapping(indices).setIndicesOptions(options), false);
verify(getMapping(indices).setIndicesOptions(options), false);
verify(getSettings(indices).setIndicesOptions(options), false);
assertAcked(prepareCreate("foobar"));
client().prepareIndex("foobar", "type", "1").setSource("k", "v").setRefreshPolicy(IMMEDIATE).get();
// Verify defaults for wildcards, with one wildcard expression and one existing index
indices = new String[] { "foo*" };
verify(search(indices), false, 1);
verify(msearch(null, indices), false, 1);
verify(clearCache(indices), false);
verify(_flush(indices), false);
verify(segments(indices), false);
verify(stats(indices), false);
verify(forceMerge(indices), false);
verify(refreshBuilder(indices), false);
verify(validateQuery(indices), false);
verify(aliasExists(indices), false);
verify(typesExists(indices), false);
verify(getAliases(indices), false);
verify(getFieldMapping(indices), false);
verify(getMapping(indices), false);
verify(getSettings(indices).setIndicesOptions(options), false);
// Verify defaults for wildcards, with two wildcard expression and one existing index
indices = new String[] { "foo*", "bar*" };
verify(search(indices), false, 1);
verify(msearch(null, indices), false, 1);
verify(clearCache(indices), false);
verify(_flush(indices), false);
verify(segments(indices), false);
verify(stats(indices), false);
verify(forceMerge(indices), false);
verify(refreshBuilder(indices), false);
verify(validateQuery(indices), true);
verify(aliasExists(indices), false);
verify(typesExists(indices), false);
verify(getAliases(indices), false);
verify(getFieldMapping(indices), false);
verify(getMapping(indices), false);
verify(getSettings(indices).setIndicesOptions(options), false);
// Now force allow_no_indices=true
options = IndicesOptions.fromOptions(false, true, true, false);
verify(search(indices).setIndicesOptions(options), false, 1);
verify(msearch(options, indices).setIndicesOptions(options), false, 1);
verify(clearCache(indices).setIndicesOptions(options), false);
verify(_flush(indices).setIndicesOptions(options), false);
verify(segments(indices).setIndicesOptions(options), false);
verify(stats(indices).setIndicesOptions(options), false);
verify(forceMerge(indices).setIndicesOptions(options), false);
verify(refreshBuilder(indices).setIndicesOptions(options), false);
verify(validateQuery(indices).setIndicesOptions(options), false);
verify(aliasExists(indices).setIndicesOptions(options), false);
verify(typesExists(indices).setIndicesOptions(options), false);
verify(getAliases(indices).setIndicesOptions(options), false);
verify(getFieldMapping(indices).setIndicesOptions(options), false);
verify(getMapping(indices).setIndicesOptions(options), false);
verify(getSettings(indices).setIndicesOptions(options), false);
}
Aggregations