36
36
import java .util .List ;
37
37
import java .util .Locale ;
38
38
39
+ import static org .elasticsearch .indices .recovery .RecoverySettings .INDICES_RECOVERY_SOURCE_ENABLED_SETTING ;
40
+
39
41
public class SourceFieldMapper extends MetadataFieldMapper {
40
42
public static final NodeFeature SYNTHETIC_SOURCE_FALLBACK = new NodeFeature ("mapper.source.synthetic_source_fallback" );
41
43
public static final NodeFeature SYNTHETIC_SOURCE_STORED_FIELDS_ADVANCE_FIX = new NodeFeature (
@@ -61,23 +63,53 @@ private enum Mode {
61
63
Explicit .IMPLICIT_TRUE ,
62
64
Strings .EMPTY_ARRAY ,
63
65
Strings .EMPTY_ARRAY ,
64
- null
66
+ null ,
67
+ true
68
+ );
69
+
70
+ private static final SourceFieldMapper DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
71
+ null ,
72
+ Explicit .IMPLICIT_TRUE ,
73
+ Strings .EMPTY_ARRAY ,
74
+ Strings .EMPTY_ARRAY ,
75
+ null ,
76
+ false
65
77
);
66
78
67
79
private static final SourceFieldMapper TSDB_DEFAULT = new SourceFieldMapper (
68
80
Mode .SYNTHETIC ,
69
81
Explicit .IMPLICIT_TRUE ,
70
82
Strings .EMPTY_ARRAY ,
71
83
Strings .EMPTY_ARRAY ,
72
- IndexMode .TIME_SERIES
84
+ IndexMode .TIME_SERIES ,
85
+ true
86
+ );
87
+
88
+ private static final SourceFieldMapper TSDB_DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
89
+ Mode .SYNTHETIC ,
90
+ Explicit .IMPLICIT_TRUE ,
91
+ Strings .EMPTY_ARRAY ,
92
+ Strings .EMPTY_ARRAY ,
93
+ IndexMode .TIME_SERIES ,
94
+ false
73
95
);
74
96
75
97
private static final SourceFieldMapper LOGSDB_DEFAULT = new SourceFieldMapper (
76
98
Mode .SYNTHETIC ,
77
99
Explicit .IMPLICIT_TRUE ,
78
100
Strings .EMPTY_ARRAY ,
79
101
Strings .EMPTY_ARRAY ,
80
- IndexMode .LOGSDB
102
+ IndexMode .LOGSDB ,
103
+ true
104
+ );
105
+
106
+ private static final SourceFieldMapper LOGSDB_DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
107
+ Mode .SYNTHETIC ,
108
+ Explicit .IMPLICIT_TRUE ,
109
+ Strings .EMPTY_ARRAY ,
110
+ Strings .EMPTY_ARRAY ,
111
+ IndexMode .LOGSDB ,
112
+ false
81
113
);
82
114
83
115
/*
@@ -89,7 +121,17 @@ private enum Mode {
89
121
Explicit .IMPLICIT_TRUE ,
90
122
Strings .EMPTY_ARRAY ,
91
123
Strings .EMPTY_ARRAY ,
92
- IndexMode .TIME_SERIES
124
+ IndexMode .TIME_SERIES ,
125
+ true
126
+ );
127
+
128
+ private static final SourceFieldMapper TSDB_LEGACY_DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
129
+ null ,
130
+ Explicit .IMPLICIT_TRUE ,
131
+ Strings .EMPTY_ARRAY ,
132
+ Strings .EMPTY_ARRAY ,
133
+ IndexMode .TIME_SERIES ,
134
+ false
93
135
);
94
136
95
137
public static class Defaults {
@@ -148,11 +190,19 @@ public static class Builder extends MetadataFieldMapper.Builder {
148
190
149
191
private final boolean supportsNonDefaultParameterValues ;
150
192
151
- public Builder (IndexMode indexMode , final Settings settings , boolean supportsCheckForNonDefaultParams ) {
193
+ private final boolean enableRecoverySource ;
194
+
195
+ public Builder (
196
+ IndexMode indexMode ,
197
+ final Settings settings ,
198
+ boolean supportsCheckForNonDefaultParams ,
199
+ boolean enableRecoverySource
200
+ ) {
152
201
super (Defaults .NAME );
153
202
this .indexMode = indexMode ;
154
203
this .supportsNonDefaultParameterValues = supportsCheckForNonDefaultParams == false
155
204
|| settings .getAsBoolean (LOSSY_PARAMETERS_ALLOWED_SETTING_NAME , true );
205
+ this .enableRecoverySource = enableRecoverySource ;
156
206
}
157
207
158
208
public Builder setSynthetic () {
@@ -218,7 +268,8 @@ public SourceFieldMapper build() {
218
268
enabled .get (),
219
269
includes .getValue ().toArray (Strings .EMPTY_ARRAY ),
220
270
excludes .getValue ().toArray (Strings .EMPTY_ARRAY ),
221
- indexMode
271
+ indexMode ,
272
+ enableRecoverySource
222
273
);
223
274
if (indexMode != null ) {
224
275
indexMode .validateSourceFieldMapper (sourceFieldMapper );
@@ -230,23 +281,25 @@ public SourceFieldMapper build() {
230
281
231
282
public static final TypeParser PARSER = new ConfigurableTypeParser (c -> {
232
283
var indexMode = c .getIndexSettings ().getMode ();
284
+ boolean enableRecoverySource = INDICES_RECOVERY_SOURCE_ENABLED_SETTING .get (c .getSettings ());
233
285
if (indexMode .isSyntheticSourceEnabled ()) {
234
286
if (indexMode == IndexMode .TIME_SERIES ) {
235
287
if (c .getIndexSettings ().getIndexVersionCreated ().onOrAfter (IndexVersions .V_8_7_0 )) {
236
- return TSDB_DEFAULT ;
288
+ return enableRecoverySource ? TSDB_DEFAULT : TSDB_DEFAULT_NO_RECOVERY_SOURCE ;
237
289
} else {
238
- return TSDB_LEGACY_DEFAULT ;
290
+ return enableRecoverySource ? TSDB_LEGACY_DEFAULT : TSDB_LEGACY_DEFAULT_NO_RECOVERY_SOURCE ;
239
291
}
240
292
} else if (indexMode == IndexMode .LOGSDB ) {
241
- return LOGSDB_DEFAULT ;
293
+ return enableRecoverySource ? LOGSDB_DEFAULT : LOGSDB_DEFAULT_NO_RECOVERY_SOURCE ;
242
294
}
243
295
}
244
- return DEFAULT ;
296
+ return enableRecoverySource ? DEFAULT : DEFAULT_NO_RECOVERY_SOURCE ;
245
297
},
246
298
c -> new Builder (
247
299
c .getIndexSettings ().getMode (),
248
300
c .getSettings (),
249
- c .indexVersionCreated ().onOrAfter (IndexVersions .SOURCE_MAPPER_LOSSY_PARAMS_CHECK )
301
+ c .indexVersionCreated ().onOrAfter (IndexVersions .SOURCE_MAPPER_LOSSY_PARAMS_CHECK ),
302
+ INDICES_RECOVERY_SOURCE_ENABLED_SETTING .get (c .getSettings ())
250
303
)
251
304
);
252
305
@@ -299,8 +352,16 @@ public BlockLoader blockLoader(BlockLoaderContext blContext) {
299
352
private final SourceFilter sourceFilter ;
300
353
301
354
private final IndexMode indexMode ;
302
-
303
- private SourceFieldMapper (Mode mode , Explicit <Boolean > enabled , String [] includes , String [] excludes , IndexMode indexMode ) {
355
+ private final boolean enableRecoverySource ;
356
+
357
+ private SourceFieldMapper (
358
+ Mode mode ,
359
+ Explicit <Boolean > enabled ,
360
+ String [] includes ,
361
+ String [] excludes ,
362
+ IndexMode indexMode ,
363
+ boolean enableRecoverySource
364
+ ) {
304
365
super (new SourceFieldType ((enabled .explicit () && enabled .value ()) || (enabled .explicit () == false && mode != Mode .DISABLED )));
305
366
assert enabled .explicit () == false || mode == null ;
306
367
this .mode = mode ;
@@ -313,6 +374,7 @@ private SourceFieldMapper(Mode mode, Explicit<Boolean> enabled, String[] include
313
374
}
314
375
this .complete = stored () && sourceFilter == null ;
315
376
this .indexMode = indexMode ;
377
+ this .enableRecoverySource = enableRecoverySource ;
316
378
}
317
379
318
380
private static SourceFilter buildSourceFilter (String [] includes , String [] excludes ) {
@@ -357,7 +419,7 @@ public void preParse(DocumentParserContext context) throws IOException {
357
419
context .doc ().add (new StoredField (fieldType ().name (), ref .bytes , ref .offset , ref .length ));
358
420
}
359
421
360
- if (originalSource != null && adaptedSource != originalSource ) {
422
+ if (enableRecoverySource && originalSource != null && adaptedSource != originalSource ) {
361
423
// if we omitted source or modified it we add the _recovery_source to ensure we have it for ops based recovery
362
424
BytesRef ref = originalSource .toBytesRef ();
363
425
context .doc ().add (new StoredField (RECOVERY_SOURCE_NAME , ref .bytes , ref .offset , ref .length ));
@@ -385,7 +447,7 @@ protected String contentType() {
385
447
386
448
@ Override
387
449
public FieldMapper .Builder getMergeBuilder () {
388
- return new Builder (indexMode , Settings .EMPTY , false ).init (this );
450
+ return new Builder (indexMode , Settings .EMPTY , false , enableRecoverySource ).init (this );
389
451
}
390
452
391
453
/**
0 commit comments