9
9
package org .elasticsearch .action .support ;
10
10
11
11
import org .elasticsearch .ElasticsearchParseException ;
12
+ import org .elasticsearch .TransportVersion ;
12
13
import org .elasticsearch .TransportVersions ;
13
14
import org .elasticsearch .common .io .stream .StreamInput ;
14
15
import org .elasticsearch .common .io .stream .StreamOutput ;
16
+ import org .elasticsearch .common .io .stream .Writeable ;
15
17
import org .elasticsearch .common .logging .DeprecationCategory ;
16
18
import org .elasticsearch .common .logging .DeprecationLogger ;
17
19
import org .elasticsearch .core .Nullable ;
45
47
* @param gatekeeperOptions, applies to all the resolved indices and defines if throttled will be included and if certain type of
46
48
* aliases or indices are allowed, or they will throw an error. It acts as a gatekeeper when an action
47
49
* does not support certain options.
50
+ * @param crossProjectModeOptions, applies to all the indices and adds logic specific for cross-project search. These options are
51
+ * internal-only and can change over the lifetime of a single request.
48
52
*/
49
53
public record IndicesOptions (
50
54
ConcreteTargetOptions concreteTargetOptions ,
51
55
WildcardOptions wildcardOptions ,
52
- GatekeeperOptions gatekeeperOptions
56
+ GatekeeperOptions gatekeeperOptions ,
57
+ CrossProjectModeOptions crossProjectModeOptions
53
58
) implements ToXContentFragment {
54
59
55
60
public static IndicesOptions .Builder builder () {
@@ -413,6 +418,37 @@ public static Builder builder(GatekeeperOptions gatekeeperOptions) {
413
418
}
414
419
}
415
420
421
+ /**
422
+ * The cross-project mode options are internal-only options that apply on all indices that have been selected by the other Options.
423
+ * These options may contextually change over the lifetime of the request.
424
+ * @param resolveIndexExpression determines that the index expression must be resolved for cross-project requests, defaults to false.
425
+ */
426
+ public record CrossProjectModeOptions (boolean resolveIndexExpression ) implements Writeable {
427
+
428
+ public static final CrossProjectModeOptions DEFAULT = new CrossProjectModeOptions (false );
429
+
430
+ private static final TransportVersion INDICES_OPTIONS_RESOLUTION_MODE = TransportVersion .fromName (
431
+ "indices_options_resolution_mode"
432
+ );
433
+
434
+ private static final String INDEX_EXPRESSION_NAME = "resolve_cross_project_index_expression" ;
435
+
436
+ @ Override
437
+ public void writeTo (StreamOutput out ) throws IOException {
438
+ if (out .getTransportVersion ().supports (INDICES_OPTIONS_RESOLUTION_MODE )) {
439
+ out .writeBoolean (resolveIndexExpression );
440
+ }
441
+ }
442
+
443
+ public static CrossProjectModeOptions readFrom (StreamInput in ) throws IOException {
444
+ if (in .getTransportVersion ().supports (INDICES_OPTIONS_RESOLUTION_MODE )) {
445
+ return new CrossProjectModeOptions (in .readBoolean ());
446
+ } else {
447
+ return CrossProjectModeOptions .DEFAULT ;
448
+ }
449
+ }
450
+ }
451
+
416
452
/**
417
453
* This class is maintained for backwards compatibility and performance purposes. We use it for serialisation along with {@link Option}.
418
454
*/
@@ -463,7 +499,8 @@ private enum Option {
463
499
public static final IndicesOptions DEFAULT = new IndicesOptions (
464
500
ConcreteTargetOptions .ERROR_WHEN_UNAVAILABLE_TARGETS ,
465
501
WildcardOptions .DEFAULT ,
466
- GatekeeperOptions .DEFAULT
502
+ GatekeeperOptions .DEFAULT ,
503
+ CrossProjectModeOptions .DEFAULT
467
504
);
468
505
469
506
public static final IndicesOptions STRICT_EXPAND_OPEN = IndicesOptions .builder ()
@@ -857,6 +894,13 @@ public boolean ignoreThrottled() {
857
894
return gatekeeperOptions ().ignoreThrottled ();
858
895
}
859
896
897
+ /**
898
+ * @return whether indices will resolve to the cross-project "flat world" expression
899
+ */
900
+ public boolean resolveCrossProjectIndexExpression () {
901
+ return crossProjectModeOptions ().resolveIndexExpression ();
902
+ }
903
+
860
904
public void writeIndicesOptions (StreamOutput out ) throws IOException {
861
905
EnumSet <Option > backwardsCompatibleOptions = EnumSet .noneOf (Option .class );
862
906
if (allowNoIndices ()) {
@@ -902,6 +946,7 @@ public void writeIndicesOptions(StreamOutput out) throws IOException {
902
946
out .writeBoolean (true );
903
947
out .writeBoolean (false );
904
948
}
949
+ out .writeWriteable (crossProjectModeOptions );
905
950
}
906
951
907
952
public static IndicesOptions readIndicesOptions (StreamInput in ) throws IOException {
@@ -930,14 +975,16 @@ public static IndicesOptions readIndicesOptions(StreamInput in) throws IOExcepti
930
975
? ConcreteTargetOptions .ALLOW_UNAVAILABLE_TARGETS
931
976
: ConcreteTargetOptions .ERROR_WHEN_UNAVAILABLE_TARGETS ,
932
977
wildcardOptions ,
933
- gatekeeperOptions
978
+ gatekeeperOptions ,
979
+ CrossProjectModeOptions .readFrom (in )
934
980
);
935
981
}
936
982
937
983
public static class Builder {
938
984
private ConcreteTargetOptions concreteTargetOptions ;
939
985
private WildcardOptions wildcardOptions ;
940
986
private GatekeeperOptions gatekeeperOptions ;
987
+ private CrossProjectModeOptions crossProjectModeOptions ;
941
988
942
989
Builder () {
943
990
this (DEFAULT );
@@ -947,6 +994,7 @@ public static class Builder {
947
994
concreteTargetOptions = indicesOptions .concreteTargetOptions ;
948
995
wildcardOptions = indicesOptions .wildcardOptions ;
949
996
gatekeeperOptions = indicesOptions .gatekeeperOptions ;
997
+ crossProjectModeOptions = indicesOptions .crossProjectModeOptions ;
950
998
}
951
999
952
1000
public Builder concreteTargetOptions (ConcreteTargetOptions concreteTargetOptions ) {
@@ -974,8 +1022,13 @@ public Builder gatekeeperOptions(GatekeeperOptions.Builder generalOptions) {
974
1022
return this ;
975
1023
}
976
1024
1025
+ public Builder crossProjectModeOptions (CrossProjectModeOptions crossProjectModeOptions ) {
1026
+ this .crossProjectModeOptions = crossProjectModeOptions ;
1027
+ return this ;
1028
+ }
1029
+
977
1030
public IndicesOptions build () {
978
- return new IndicesOptions (concreteTargetOptions , wildcardOptions , gatekeeperOptions );
1031
+ return new IndicesOptions (concreteTargetOptions , wildcardOptions , gatekeeperOptions , crossProjectModeOptions );
979
1032
}
980
1033
}
981
1034
@@ -1077,7 +1130,8 @@ public static IndicesOptions fromOptions(
1077
1130
return new IndicesOptions (
1078
1131
ignoreUnavailable ? ConcreteTargetOptions .ALLOW_UNAVAILABLE_TARGETS : ConcreteTargetOptions .ERROR_WHEN_UNAVAILABLE_TARGETS ,
1079
1132
wildcards ,
1080
- gatekeeperOptions
1133
+ gatekeeperOptions ,
1134
+ CrossProjectModeOptions .DEFAULT
1081
1135
);
1082
1136
}
1083
1137
@@ -1148,14 +1202,18 @@ public static IndicesOptions fromParameters(
1148
1202
return defaultSettings ;
1149
1203
}
1150
1204
1151
- WildcardOptions wildcards = WildcardOptions .parseParameters (wildcardsString , allowNoIndicesString , defaultSettings .wildcardOptions );
1152
- GatekeeperOptions gatekeeperOptions = GatekeeperOptions .parseParameter (ignoreThrottled , defaultSettings .gatekeeperOptions );
1205
+ var wildcards = WildcardOptions .parseParameters (wildcardsString , allowNoIndicesString , defaultSettings .wildcardOptions );
1206
+ var gatekeeperOptions = GatekeeperOptions .parseParameter (ignoreThrottled , defaultSettings .gatekeeperOptions );
1207
+ var crossProjectModeOptions = defaultSettings .crossProjectModeOptions != null
1208
+ ? defaultSettings .crossProjectModeOptions
1209
+ : CrossProjectModeOptions .DEFAULT ;
1153
1210
1154
1211
// note that allowAliasesToMultipleIndices is not exposed, always true (only for internal use)
1155
1212
return IndicesOptions .builder ()
1156
1213
.concreteTargetOptions (ConcreteTargetOptions .fromParameter (ignoreUnavailableString , defaultSettings .concreteTargetOptions ))
1157
1214
.wildcardOptions (wildcards )
1158
1215
.gatekeeperOptions (gatekeeperOptions )
1216
+ .crossProjectModeOptions (crossProjectModeOptions )
1159
1217
.build ();
1160
1218
}
1161
1219
@@ -1421,6 +1479,8 @@ public String toString() {
1421
1479
+ allowSelectors ()
1422
1480
+ ", include_failure_indices="
1423
1481
+ includeFailureIndices ()
1482
+ + ", resolve_cross_project_index_expression="
1483
+ + resolveCrossProjectIndexExpression ()
1424
1484
+ ']' ;
1425
1485
}
1426
1486
}
0 commit comments