Search in sources :

Example 16 with IndicesOptions

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

the class SnapshotRequestsTests method testCreateSnapshotRequestParsing.

public void testCreateSnapshotRequestParsing() throws IOException {
    CreateSnapshotRequest request = new CreateSnapshotRequest("test-repo", "test-snap");
    XContentBuilder builder = jsonBuilder().startObject();
    if (randomBoolean()) {
        builder.field("indices", "foo,bar,baz");
    } else {
        builder.startArray("indices");
        builder.value("foo");
        builder.value("bar");
        builder.value("baz");
        builder.endArray();
    }
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
    if (indicesOptions.expandWildcardsClosed()) {
        if (indicesOptions.expandWildcardsOpen()) {
            builder.field("expand_wildcards", "all");
        } else {
            builder.field("expand_wildcards", "closed");
        }
    } else {
        if (indicesOptions.expandWildcardsOpen()) {
            builder.field("expand_wildcards", "open");
        } else {
            builder.field("expand_wildcards", "none");
        }
    }
    builder.field("allow_no_indices", indicesOptions.allowNoIndices());
    boolean partial = randomBoolean();
    builder.field("partial", partial);
    builder.startObject("settings").field("set1", "val1").endObject();
    builder.startObject("index_settings").field("set1", "val2").endObject();
    if (randomBoolean()) {
        builder.field("ignore_index_settings", "set2,set3");
    } else {
        builder.startArray("ignore_index_settings");
        builder.value("set2");
        builder.value("set3");
        builder.endArray();
    }
    BytesReference bytes = builder.endObject().bytes();
    request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2());
    assertEquals("test-repo", request.repository());
    assertEquals("test-snap", request.snapshot());
    assertArrayEquals(request.indices(), new String[] { "foo", "bar", "baz" });
    assertEquals(partial, request.partial());
    assertEquals("val1", request.settings().get("set1"));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 17 with IndicesOptions

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

the class UpdateByQueryRequestTests method testUpdateByQueryRequestImplementsIndicesRequestReplaceable.

public void testUpdateByQueryRequestImplementsIndicesRequestReplaceable() {
    int numIndices = between(1, 100);
    String[] indices = new String[numIndices];
    for (int i = 0; i < numIndices; i++) {
        indices[i] = randomSimpleString(random(), 1, 30);
    }
    SearchRequest searchRequest = new SearchRequest(indices);
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
    searchRequest.indicesOptions(indicesOptions);
    UpdateByQueryRequest request = new UpdateByQueryRequest(searchRequest);
    for (int i = 0; i < numIndices; i++) {
        assertEquals(indices[i], request.indices()[i]);
    }
    assertSame(indicesOptions, request.indicesOptions());
    assertSame(request.indicesOptions(), request.getSearchRequest().indicesOptions());
    int numNewIndices = between(1, 100);
    String[] newIndices = new String[numNewIndices];
    for (int i = 0; i < numNewIndices; i++) {
        newIndices[i] = randomSimpleString(random(), 1, 30);
    }
    request.indices(newIndices);
    for (int i = 0; i < numNewIndices; i++) {
        ;
        assertEquals(newIndices[i], request.indices()[i]);
    }
    for (int i = 0; i < numNewIndices; i++) {
        ;
        assertEquals(newIndices[i], request.getSearchRequest().indices()[i]);
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) TestUtil.randomSimpleString(org.apache.lucene.util.TestUtil.randomSimpleString) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 18 with IndicesOptions

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

the class IndicesOptionsIntegrationIT method testCloseApiSpecifiedIndices.

// For now don't handle closed indices
public void testCloseApiSpecifiedIndices() throws Exception {
    createIndex("test1", "test2");
    ensureGreen();
    verify(search("test1", "test2"), false);
    assertAcked(client().admin().indices().prepareClose("test2").get());
    verify(search("test1", "test2"), true);
    IndicesOptions options = IndicesOptions.fromOptions(true, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed());
    verify(search("test1", "test2").setIndicesOptions(options), false);
    verify(search(), false);
    verify(search("t*"), false);
}
Also used : IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 19 with IndicesOptions

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

the class IndicesOptionsIntegrationIT method testWildcardBehaviourSnapshotRestore.

public void testWildcardBehaviourSnapshotRestore() throws Exception {
    createIndex("foobar");
    ensureGreen("foobar");
    waitForRelocation();
    PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("dummy-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    client().admin().cluster().prepareCreateSnapshot("dummy-repo", "snap1").setWaitForCompletion(true).get();
    IndicesOptions options = IndicesOptions.fromOptions(false, false, true, false);
    verify(snapshot("snap2", "foo*", "bar*").setIndicesOptions(options), true);
    verify(restore("snap1", "foo*", "bar*").setIndicesOptions(options), true);
    options = IndicesOptions.strictExpandOpen();
    verify(snapshot("snap2", "foo*", "bar*").setIndicesOptions(options), false);
    verify(restore("snap2", "foo*", "bar*").setIndicesOptions(options), false);
    assertAcked(prepareCreate("barbaz"));
    //TODO: temporary work-around for #5531
    ensureGreen("barbaz");
    waitForRelocation();
    options = IndicesOptions.fromOptions(false, false, true, false);
    verify(snapshot("snap3", "foo*", "bar*").setIndicesOptions(options), false);
    verify(restore("snap3", "foo*", "bar*").setIndicesOptions(options), false);
    options = IndicesOptions.fromOptions(false, false, true, false);
    verify(snapshot("snap4", "foo*", "baz*").setIndicesOptions(options), true);
    verify(restore("snap3", "foo*", "baz*").setIndicesOptions(options), true);
}
Also used : PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 20 with IndicesOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project crate by crate.

the class SnapshotRestoreDDLDispatcher method dispatch.

public CompletableFuture<Long> dispatch(final CreateSnapshotAnalyzedStatement statement) {
    final CompletableFuture<Long> resultFuture = new CompletableFuture<>();
    boolean waitForCompletion = statement.snapshotSettings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
    boolean ignoreUnavailable = statement.snapshotSettings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
    // ignore_unavailable as set by statement
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
    CreateSnapshotRequest request = new CreateSnapshotRequest(statement.snapshotId().getRepository(), statement.snapshotId().getSnapshot()).includeGlobalState(statement.includeMetadata()).waitForCompletion(waitForCompletion).indices(statement.indices()).indicesOptions(indicesOptions).settings(statement.snapshotSettings());
    //noinspection ThrowableResultOfMethodCallIgnored
    assert request.validate() == null : "invalid CREATE SNAPSHOT statement";
    transportActionProvider.transportCreateSnapshotAction().execute(request, new ActionListener<CreateSnapshotResponse>() {

        @Override
        public void onResponse(CreateSnapshotResponse createSnapshotResponse) {
            SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo();
            if (snapshotInfo == null) {
                // if wait_for_completion is false the snapshotInfo is null
                resultFuture.complete(1L);
            } else if (snapshotInfo.state() == SnapshotState.FAILED) {
                // fail request if snapshot creation failed
                String reason = createSnapshotResponse.getSnapshotInfo().reason().replaceAll("Index", "Table").replaceAll("Indices", "Tables");
                resultFuture.completeExceptionally(new CreateSnapshotException(statement.snapshotId(), reason));
            } else {
                resultFuture.complete(1L);
            }
        }

        @Override
        public void onFailure(Throwable e) {
            resultFuture.completeExceptionally(e);
        }
    });
    return resultFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) CreateSnapshotException(io.crate.exceptions.CreateSnapshotException) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) 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