Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ static void resolveIndices(
if (names.length == 1 && (Metadata.ALL.equals(names[0]) || Regex.isMatchAllPattern(names[0]))) {
names = new String[] { "**" };
}
assert indicesOptions.wildcardOptions().resolveViews() == false : "Views are not supported in ResolveIndexAction";
assert indicesOptions.indexAbstractionOptions().resolveViews() == false : "Views are not supported in ResolveIndexAction";
Set<ResolvedExpression> resolvedIndexAbstractions = resolver.resolveExpressions(
projectState.metadata(),
indicesOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ protected ClusterBlockException checkBlock(RolloverRequest request, ClusterState
.matchClosed(request.indicesOptions().expandWildcardsClosed())
.build(),
IndicesOptions.GatekeeperOptions.DEFAULT,
IndicesOptions.CrossProjectModeOptions.DEFAULT
IndicesOptions.CrossProjectModeOptions.DEFAULT,
IndicesOptions.IndexAbstractionOptions.DEFAULT
);
ResolvedExpression resolvedRolloverTarget = SelectorResolver.parseExpression(request.getRolloverTarget(), request.indicesOptions());
final IndexAbstraction indexAbstraction = projectMetadata.getIndicesLookup().get(resolvedRolloverTarget.resource());
Expand Down Expand Up @@ -257,7 +258,8 @@ protected void masterOperation(
IndicesOptions.ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS,
IndicesOptions.WildcardOptions.builder().matchClosed(true).allowEmptyExpressions(false).build(),
IndicesOptions.GatekeeperOptions.DEFAULT,
IndicesOptions.CrossProjectModeOptions.DEFAULT
IndicesOptions.CrossProjectModeOptions.DEFAULT,
IndicesOptions.IndexAbstractionOptions.DEFAULT
);
// Make sure to recombine any selectors on the stats request
IndicesStatsRequest statsRequest = new IndicesStatsRequest().indices(resolvedRolloverTarget.combined())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@
* does not support certain options.
* @param crossProjectModeOptions, applies to all the indices and adds logic specific for cross-project search. These options are
* internal-only and can change over the lifetime of a single request.
* @param indexAbstractionOptions, controls which types of index abstractions (aliases, views, etc.) participate in index
* resolution. These options apply to both concrete and wildcard resolution paths.
*/
public record IndicesOptions(
ConcreteTargetOptions concreteTargetOptions,
WildcardOptions wildcardOptions,
GatekeeperOptions gatekeeperOptions,
CrossProjectModeOptions crossProjectModeOptions
CrossProjectModeOptions crossProjectModeOptions,
IndexAbstractionOptions indexAbstractionOptions
) implements ToXContentFragment {

public static IndicesOptions.Builder builder() {
Expand Down Expand Up @@ -97,21 +100,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
* @param resolveAliases, aliases will be included in the result, if false we treat them like they do not exist
* @param allowEmptyExpressions, when an expression does not result in any indices, if false it throws an error if true it treats it as
* an empty result
* @param resolveViews, views will be included in the result, if false we treat them like they do not exist
*/
public record WildcardOptions(
boolean matchOpen,
boolean matchClosed,
boolean includeHidden,
boolean resolveAliases,
boolean allowEmptyExpressions,
boolean resolveViews
boolean allowEmptyExpressions
) implements ToXContentFragment {

public static final String EXPAND_WILDCARDS = "expand_wildcards";
public static final String ALLOW_NO_INDICES = "allow_no_indices";

public static final WildcardOptions DEFAULT = new WildcardOptions(true, false, false, true, true, false);
public static final WildcardOptions DEFAULT = new WildcardOptions(true, false, false, true, true);

public static WildcardOptions parseParameters(Object expandWildcards, Object allowNoIndices, WildcardOptions defaultOptions) {
if (expandWildcards == null && allowNoIndices == null) {
Expand Down Expand Up @@ -180,7 +181,6 @@ public static class Builder {
private boolean includeHidden;
private boolean resolveAliases;
private boolean allowEmptyExpressions;
private boolean resolveViews;

Builder() {
this(DEFAULT);
Expand All @@ -192,7 +192,6 @@ public static class Builder {
includeHidden = options.includeHidden;
resolveAliases = options.resolveAliases;
allowEmptyExpressions = options.allowEmptyExpressions;
resolveViews = options.resolveViews;
}

/**
Expand Down Expand Up @@ -248,14 +247,6 @@ public Builder matchNone() {
return this;
}

/**
* Resolve views. Defaults to false
*/
public Builder resolveViews(boolean resolveViews) {
this.resolveViews = resolveViews;
return this;
}

/**
* Maximises the resolution of indices, we will match open, closed and hidden targets.
*/
Expand Down Expand Up @@ -293,7 +284,7 @@ public Builder expandStates(String[] expandStates) {
}

public WildcardOptions build() {
return new WildcardOptions(matchOpen, matchClosed, includeHidden, resolveAliases, allowEmptyExpressions, resolveViews);
return new WildcardOptions(matchOpen, matchClosed, includeHidden, resolveAliases, allowEmptyExpressions);
}
}

Expand Down Expand Up @@ -460,6 +451,48 @@ public static CrossProjectModeOptions readFrom(StreamInput in) throws IOExceptio
}
}

/**
* Controls which types of index abstractions participate in index resolution. These options apply uniformly
* to both concrete target and wildcard resolution paths.
* @param resolveViews, views will be included in the result, if false we treat them like they do not exist. Defaults to false.
*/
public record IndexAbstractionOptions(boolean resolveViews) {

public static final IndexAbstractionOptions DEFAULT = new IndexAbstractionOptions(false);

public static class Builder {
private boolean resolveViews;

Builder() {
this(DEFAULT);
}

Builder(IndexAbstractionOptions options) {
resolveViews = options.resolveViews;
}

/**
* Views will be included in the result. Defaults to false.
*/
public Builder resolveViews(boolean resolveViews) {
this.resolveViews = resolveViews;
return this;
}

public IndexAbstractionOptions build() {
return new IndexAbstractionOptions(resolveViews);
}
}

public static Builder builder() {
return new Builder();
}

public static Builder builder(IndexAbstractionOptions indexAbstractionOptions) {
return new Builder(indexAbstractionOptions);
}
}

/**
* This class is maintained for backwards compatibility and performance purposes. We use it for serialisation along with {@link Option}.
*/
Expand Down Expand Up @@ -511,7 +544,8 @@ private enum Option {
ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS,
WildcardOptions.DEFAULT,
GatekeeperOptions.DEFAULT,
CrossProjectModeOptions.DEFAULT
CrossProjectModeOptions.DEFAULT,
IndexAbstractionOptions.DEFAULT
);

public static final IndicesOptions STRICT_EXPAND_OPEN = IndicesOptions.builder()
Expand Down Expand Up @@ -997,7 +1031,8 @@ public static IndicesOptions readIndicesOptions(StreamInput in) throws IOExcepti
: ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS,
wildcardOptions,
gatekeeperOptions,
CrossProjectModeOptions.readFrom(in)
CrossProjectModeOptions.readFrom(in),
IndexAbstractionOptions.DEFAULT
);
}

Expand All @@ -1006,6 +1041,7 @@ public static class Builder {
private WildcardOptions wildcardOptions;
private GatekeeperOptions gatekeeperOptions;
private CrossProjectModeOptions crossProjectModeOptions;
private IndexAbstractionOptions indexAbstractionOptions;

Builder() {
this(DEFAULT);
Expand All @@ -1016,6 +1052,7 @@ public static class Builder {
wildcardOptions = indicesOptions.wildcardOptions;
gatekeeperOptions = indicesOptions.gatekeeperOptions;
crossProjectModeOptions = indicesOptions.crossProjectModeOptions;
indexAbstractionOptions = indicesOptions.indexAbstractionOptions;
}

public Builder concreteTargetOptions(ConcreteTargetOptions concreteTargetOptions) {
Expand Down Expand Up @@ -1048,8 +1085,24 @@ public Builder crossProjectModeOptions(CrossProjectModeOptions crossProjectModeO
return this;
}

public Builder indexAbstractionOptions(IndexAbstractionOptions indexAbstractionOptions) {
this.indexAbstractionOptions = indexAbstractionOptions;
return this;
}

public Builder indexAbstractionOptions(IndexAbstractionOptions.Builder indexAbstractionOptions) {
this.indexAbstractionOptions = indexAbstractionOptions.build();
return this;
}

public IndicesOptions build() {
return new IndicesOptions(concreteTargetOptions, wildcardOptions, gatekeeperOptions, crossProjectModeOptions);
return new IndicesOptions(
concreteTargetOptions,
wildcardOptions,
gatekeeperOptions,
crossProjectModeOptions,
indexAbstractionOptions
);
}
}

Expand Down Expand Up @@ -1152,7 +1205,8 @@ public static IndicesOptions fromOptions(
ignoreUnavailable ? ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS : ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS,
wildcards,
gatekeeperOptions,
CrossProjectModeOptions.DEFAULT
CrossProjectModeOptions.DEFAULT,
IndexAbstractionOptions.DEFAULT
);
}

Expand Down Expand Up @@ -1235,6 +1289,7 @@ public static IndicesOptions fromParameters(
.wildcardOptions(wildcards)
.gatekeeperOptions(gatekeeperOptions)
.crossProjectModeOptions(crossProjectModeOptions)
.indexAbstractionOptions(defaultSettings.indexAbstractionOptions)
.build();
}

Expand Down Expand Up @@ -1510,6 +1565,8 @@ public String toString() {
+ allowSelectors()
+ ", include_failure_indices="
+ includeFailureIndices()
+ ", resolve_views="
+ indexAbstractionOptions.resolveViews()
+ ", resolve_cross_project_index_expression="
+ resolveCrossProjectIndexExpression()
+ ']';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private static boolean isIndexVisible(
throw new IllegalStateException("could not resolve index abstraction [" + index + "]");
}
if (indexAbstraction.getType() == IndexAbstraction.Type.VIEW) {
return indicesOptions.wildcardOptions().resolveViews();
return indicesOptions.indexAbstractionOptions().resolveViews();
}
final boolean isHidden = indexAbstraction.isHidden();
boolean isVisible = isWildcardExpression == false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ private static boolean ensureAliasOrIndexExists(Context context, String name, In
throw infe;
}
}
if (indexAbstraction.getType() == Type.VIEW && context.getOptions().wildcardOptions().resolveViews() == false) {
if (indexAbstraction.getType() == Type.VIEW && context.getOptions().indexAbstractionOptions().resolveViews() == false) {
if (ignoreUnavailable) {
return false;
} else {
Expand Down Expand Up @@ -1797,7 +1797,7 @@ private static boolean shouldExpandToIndexAbstraction(
String wildcardExpression,
IndexAbstraction indexAbstraction
) {
if (context.getOptions().wildcardOptions().resolveViews() == false && indexAbstraction.getType() == Type.VIEW) {
if (context.getOptions().indexAbstractionOptions().resolveViews() == false && indexAbstraction.getType() == Type.VIEW) {
return false;
}
if (context.getOptions().ignoreAliases() && indexAbstraction.getType() == Type.ALIAS) {
Expand Down Expand Up @@ -1852,7 +1852,7 @@ private static Set<ResolvedExpression> expandToOpenClosed(
} else if (context.isPreserveDataStreams() && indexAbstraction.getType() == Type.DATA_STREAM) {
resources.add(new ResolvedExpression(indexAbstraction.getName(), selector));
} else if (indexAbstraction.getType() == Type.VIEW) {
if (context.getOptions().wildcardOptions().resolveViews()) {
if (context.getOptions().indexAbstractionOptions().resolveViews()) {
resources.add(new ResolvedExpression(indexAbstraction.getName(), selector));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public void testToXContent() throws IOException {
randomBoolean(),
randomBoolean(),
defaultResolveAliasForThisRequest,
randomBoolean(),
false // Specifying views in the create snapshot request is not supported
randomBoolean()
)
)
.gatekeeperOptions(IndicesOptions.GatekeeperOptions.builder().allowSelectors(false).includeFailureIndices(true).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ private RestoreSnapshotRequest randomState(RestoreSnapshotRequest instance) {
randomBoolean(),
randomBoolean(),
instance.indicesOptions().ignoreAliases() == false,
randomBoolean(),
false // Specifying views in the restore snapshot request is not supported
randomBoolean()
)
)
.gatekeeperOptions(IndicesOptions.GatekeeperOptions.builder().allowSelectors(false).includeFailureIndices(true).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.support.IndicesOptions.ConcreteTargetOptions;
import org.elasticsearch.action.support.IndicesOptions.CrossProjectModeOptions;
import org.elasticsearch.action.support.IndicesOptions.GatekeeperOptions;
import org.elasticsearch.action.support.IndicesOptions.IndexAbstractionOptions;
import org.elasticsearch.action.support.IndicesOptions.WildcardOptions;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
Expand Down Expand Up @@ -59,6 +60,7 @@ public void testSerialization() throws Exception {
.allowSelectors(randomBoolean())
)
.crossProjectModeOptions(new CrossProjectModeOptions(randomBoolean()))
.indexAbstractionOptions(IndexAbstractionOptions.builder().resolveViews(randomBoolean()))
.build();

BytesStreamOutput output = new BytesStreamOutput();
Expand All @@ -67,7 +69,10 @@ public void testSerialization() throws Exception {
StreamInput streamInput = output.bytes().streamInput();
IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(streamInput);

assertThat(indicesOptions2, equalTo(indicesOptions));
IndicesOptions expected = IndicesOptions.builder(indicesOptions)
.indexAbstractionOptions(IndexAbstractionOptions.builder(indicesOptions.indexAbstractionOptions()).resolveViews(false))
.build();
assertThat(indicesOptions2, equalTo(expected));
}
}

Expand Down Expand Up @@ -345,7 +350,6 @@ public void testToXContent() throws IOException {
randomBoolean(),
randomBoolean(),
randomBoolean(),
randomBoolean(),
randomBoolean()
);
GatekeeperOptions gatekeeperOptions = new GatekeeperOptions(
Expand All @@ -356,12 +360,14 @@ public void testToXContent() throws IOException {
randomBoolean()
);
CrossProjectModeOptions crossProjectModeOptions = new CrossProjectModeOptions(randomBoolean());
IndexAbstractionOptions indexAbstractionOptions = new IndexAbstractionOptions(randomBoolean());

IndicesOptions indicesOptions = new IndicesOptions(
concreteTargetOptions,
wildcardOptions,
gatekeeperOptions,
crossProjectModeOptions
crossProjectModeOptions,
indexAbstractionOptions
);

XContentType type = randomFrom(XContentType.values());
Expand All @@ -385,7 +391,6 @@ public void testFromXContent() throws IOException {
randomBoolean(),
randomBoolean(),
randomBoolean(),
randomBoolean(),
randomBoolean()
);
ConcreteTargetOptions concreteTargetOptions = new ConcreteTargetOptions(randomBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,8 @@ public void testIgnoreThrottled() {
IndicesOptions.ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS,
IndicesOptions.WildcardOptions.DEFAULT,
IndicesOptions.GatekeeperOptions.builder().ignoreThrottled(true).build(),
IndicesOptions.CrossProjectModeOptions.DEFAULT
IndicesOptions.CrossProjectModeOptions.DEFAULT,
IndicesOptions.IndexAbstractionOptions.DEFAULT
),
"ind*",
"test-index"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public static class Request extends LocalClusterStateRequest implements IndicesR
private String[] indices = new String[0];
private ResolvedIndexExpressions resolvedIndexExpressions;
private static final IndicesOptions VIEW_INDICES_OPTIONS = IndicesOptions.builder()
.wildcardOptions(IndicesOptions.WildcardOptions.builder().resolveViews(true).allowEmptyExpressions(true))
.wildcardOptions(IndicesOptions.WildcardOptions.builder().allowEmptyExpressions(true))
.indexAbstractionOptions(IndicesOptions.IndexAbstractionOptions.builder().resolveViews(true).build())
.concreteTargetOptions(IndicesOptions.ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DeleteViewAction extends ActionType<AcknowledgedResponse> {

public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.builder()
.concreteTargetOptions(IndicesOptions.ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS)
.wildcardOptions(IndicesOptions.WildcardOptions.builder().resolveViews(true).build())
.indexAbstractionOptions(IndicesOptions.IndexAbstractionOptions.builder().resolveViews(true).build())
.build();

private DeleteViewAction() {
Expand Down
Loading
Loading