use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class SnapshotRestoreDDLDispatcher method dispatch.
public CompletableFuture<Long> dispatch(final RestoreSnapshotAnalyzedStatement analysis) {
boolean waitForCompletion = analysis.settings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
boolean ignoreUnavailable = analysis.settings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
FutureActionListener<RestoreSnapshotResponse, Long> listener = new FutureActionListener<>(Functions.constant(1L));
resolveIndexNames(analysis.restoreTables(), ignoreUnavailable, transportActionProvider.transportGetSnapshotsAction(), analysis.repositoryName()).whenComplete((List<String> indexNames, Throwable t) -> {
if (t == null) {
RestoreSnapshotRequest request = new RestoreSnapshotRequest(analysis.repositoryName(), analysis.snapshotName()).indices(indexNames).indicesOptions(indicesOptions).settings(analysis.settings()).waitForCompletion(waitForCompletion).includeGlobalState(false).includeAliases(true);
transportActionProvider.transportRestoreSnapshotAction().execute(request, listener);
} else {
listener.onFailure(t);
}
});
return listener;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project engine by craftercms.
the class SiteAwareElasticsearchService method updateIndex.
/**
* {@inheritDoc}
*/
@Override
protected void updateIndex(final SearchRequest request) {
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext == null) {
throw new IllegalStateException("Current site context not found");
}
// Generate the default alias for the current site
String aliasName = String.format(indexIdFormat, siteContext.getSiteName());
// Get the requested indices
String[] currentIndices = request.indices();
String[] updatedIndices;
if (ArrayUtils.isNotEmpty(currentIndices)) {
updatedIndices = new String[currentIndices.length + 1];
// Add the site name prefix for all indices
for (int i = 0; i < currentIndices.length; i++) {
updatedIndices[i] = addPrefix(siteContext, currentIndices[i]);
}
// Also add the default index
updatedIndices[currentIndices.length] = aliasName;
// Add the site name prefix for the boosting if needed
List<SearchSourceBuilder.IndexBoost> indexBoosts = new ArrayList<>(request.source().indexBoosts());
if (isNotEmpty(indexBoosts)) {
indexBoosts.forEach(indexBoost -> request.source().indexBoost(addPrefix(siteContext, indexBoost.getIndex()), indexBoost.getBoost()));
// Prevent missing index errors, this is needed because the original index boost can't be removed
IndicesOptions originalOptions = request.indicesOptions();
request.indicesOptions(IndicesOptions.fromOptions(true, originalOptions.allowNoIndices(), originalOptions.expandWildcardsOpen(), originalOptions.expandWildcardsClosed(), originalOptions.allowAliasesToMultipleIndices(), originalOptions.forbidClosedIndices(), originalOptions.ignoreAliases(), originalOptions.ignoreThrottled()));
}
} else {
// Only query the default index
updatedIndices = new String[] { aliasName };
}
request.indices(updatedIndices);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project crate by crate.
the class RestoreSnapshotPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row parameters, SubQueryResults subQueryResults) {
BoundRestoreSnapshot stmt = bind(restoreSnapshot, plannerContext.transactionContext(), dependencies.nodeContext(), parameters, subQueryResults, dependencies.schemas());
var settings = stmt.settings();
boolean ignoreUnavailable = IGNORE_UNAVAILABLE.get(settings);
var transportActionProvider = dependencies.transportActionProvider();
resolveIndexNames(restoreSnapshot.repository(), stmt.restoreTables(), ignoreUnavailable, transportActionProvider.transportGetSnapshotsAction()).whenComplete((ResolveIndicesAndTemplatesContext ctx, Throwable t) -> {
if (t == null) {
String[] indexNames = ctx.resolvedIndices().toArray(new String[0]);
String[] templateNames = stmt.includeTables() && stmt.restoreTables().isEmpty() ? new String[] { ALL_TEMPLATES } : ctx.resolvedTemplates().toArray(new String[0]);
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
RestoreSnapshotRequest request = new RestoreSnapshotRequest(restoreSnapshot.repository(), restoreSnapshot.snapshot()).indices(indexNames).templates(templateNames).indicesOptions(indicesOptions).settings(settings).waitForCompletion(WAIT_FOR_COMPLETION.get(settings)).includeIndices(stmt.includeTables()).includeAliases(stmt.includeTables()).includeCustomMetadata(stmt.includeCustomMetadata()).customMetadataTypes(stmt.customMetadataTypes()).includeGlobalSettings(stmt.includeGlobalSettings()).globalSettings(stmt.globalSettings());
transportActionProvider.transportRestoreSnapshotAction().execute(request, new OneRowActionListener<>(consumer, r -> new Row1(r == null ? -1L : 1L)));
}
});
}
Aggregations