Search in sources :

Example 26 with IndicesOptions

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()]);
}
Also used : Index(org.elasticsearch.index.Index) IndexClosedException(org.elasticsearch.indices.IndexClosedException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) HashSet(java.util.HashSet)

Example 27 with IndicesOptions

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);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 28 with IndicesOptions

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);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 29 with IndicesOptions

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);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 30 with IndicesOptions

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);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Aggregations

IndicesOptions (org.elasticsearch.action.support.IndicesOptions)39 ClusterState (org.elasticsearch.cluster.ClusterState)11 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)11 ClusterName (org.elasticsearch.cluster.ClusterName)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Arrays (java.util.Arrays)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)4 SearchSourceBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)4 Row (io.crate.data.Row)3 Row1 (io.crate.data.Row1)3 RowConsumer (io.crate.data.RowConsumer)3 OneRowActionListener (io.crate.execution.support.OneRowActionListener)3 DependencyCarrier (io.crate.planner.DependencyCarrier)3 Plan (io.crate.planner.Plan)3 PlannerContext (io.crate.planner.PlannerContext)3