39
39
import java .util .List ;
40
40
import java .util .Locale ;
41
41
42
- import static org .elasticsearch .indices .recovery .RecoverySettings .INDICES_RECOVERY_SOURCE_ENABLED_SETTING ;
43
-
44
42
public class SourceFieldMapper extends MetadataFieldMapper {
45
43
public static final NodeFeature SYNTHETIC_SOURCE_FALLBACK = new NodeFeature ("mapper.source.synthetic_source_fallback" );
46
44
public static final NodeFeature SYNTHETIC_SOURCE_STORED_FIELDS_ADVANCE_FIX = new NodeFeature (
@@ -88,125 +86,55 @@ public enum Mode {
88
86
Explicit .IMPLICIT_TRUE ,
89
87
Strings .EMPTY_ARRAY ,
90
88
Strings .EMPTY_ARRAY ,
91
- null ,
92
- true
89
+ null
93
90
);
94
91
95
92
private static final SourceFieldMapper DEFAULT_DISABLED = new SourceFieldMapper (
96
93
Mode .DISABLED ,
97
94
Explicit .IMPLICIT_TRUE ,
98
95
Strings .EMPTY_ARRAY ,
99
96
Strings .EMPTY_ARRAY ,
100
- null ,
101
- true
102
- );
103
-
104
- private static final SourceFieldMapper DEFAULT_DISABLED_NO_RECOVERY_SOURCE = new SourceFieldMapper (
105
- Mode .DISABLED ,
106
- Explicit .IMPLICIT_TRUE ,
107
- Strings .EMPTY_ARRAY ,
108
- Strings .EMPTY_ARRAY ,
109
- null ,
110
- false
97
+ null
111
98
);
112
99
113
100
private static final SourceFieldMapper DEFAULT_SYNTHETIC = new SourceFieldMapper (
114
101
Mode .SYNTHETIC ,
115
102
Explicit .IMPLICIT_TRUE ,
116
103
Strings .EMPTY_ARRAY ,
117
104
Strings .EMPTY_ARRAY ,
118
- null ,
119
- true
120
- );
121
-
122
- private static final SourceFieldMapper DEFAULT_SYNTHETIC_NO_RECOVERY_SOURCE = new SourceFieldMapper (
123
- Mode .SYNTHETIC ,
124
- Explicit .IMPLICIT_TRUE ,
125
- Strings .EMPTY_ARRAY ,
126
- Strings .EMPTY_ARRAY ,
127
- null ,
128
- false
129
- );
130
-
131
- private static final SourceFieldMapper DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
132
- null ,
133
- Explicit .IMPLICIT_TRUE ,
134
- Strings .EMPTY_ARRAY ,
135
- Strings .EMPTY_ARRAY ,
136
- null ,
137
- false
105
+ null
138
106
);
139
107
140
108
private static final SourceFieldMapper TSDB_DEFAULT = new SourceFieldMapper (
141
109
Mode .SYNTHETIC ,
142
110
Explicit .IMPLICIT_TRUE ,
143
111
Strings .EMPTY_ARRAY ,
144
112
Strings .EMPTY_ARRAY ,
145
- IndexMode .TIME_SERIES ,
146
- true
113
+ IndexMode .TIME_SERIES
147
114
);
148
115
149
116
private static final SourceFieldMapper TSDB_DEFAULT_STORED = new SourceFieldMapper (
150
117
Mode .STORED ,
151
118
Explicit .IMPLICIT_TRUE ,
152
119
Strings .EMPTY_ARRAY ,
153
120
Strings .EMPTY_ARRAY ,
154
- IndexMode .TIME_SERIES ,
155
- true
156
- );
157
-
158
- private static final SourceFieldMapper TSDB_DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
159
- Mode .SYNTHETIC ,
160
- Explicit .IMPLICIT_TRUE ,
161
- Strings .EMPTY_ARRAY ,
162
- Strings .EMPTY_ARRAY ,
163
- IndexMode .TIME_SERIES ,
164
- false
165
- );
166
-
167
- private static final SourceFieldMapper TSDB_DEFAULT_NO_RECOVERY_SOURCE_STORED = new SourceFieldMapper (
168
- Mode .STORED ,
169
- Explicit .IMPLICIT_TRUE ,
170
- Strings .EMPTY_ARRAY ,
171
- Strings .EMPTY_ARRAY ,
172
- IndexMode .TIME_SERIES ,
173
- false
121
+ IndexMode .TIME_SERIES
174
122
);
175
123
176
124
private static final SourceFieldMapper LOGSDB_DEFAULT = new SourceFieldMapper (
177
125
Mode .SYNTHETIC ,
178
126
Explicit .IMPLICIT_TRUE ,
179
127
Strings .EMPTY_ARRAY ,
180
128
Strings .EMPTY_ARRAY ,
181
- IndexMode .LOGSDB ,
182
- true
129
+ IndexMode .LOGSDB
183
130
);
184
131
185
132
private static final SourceFieldMapper LOGSDB_DEFAULT_STORED = new SourceFieldMapper (
186
133
Mode .STORED ,
187
134
Explicit .IMPLICIT_TRUE ,
188
135
Strings .EMPTY_ARRAY ,
189
136
Strings .EMPTY_ARRAY ,
190
- IndexMode .LOGSDB ,
191
- true
192
- );
193
-
194
- private static final SourceFieldMapper LOGSDB_DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
195
- Mode .SYNTHETIC ,
196
- Explicit .IMPLICIT_TRUE ,
197
- Strings .EMPTY_ARRAY ,
198
- Strings .EMPTY_ARRAY ,
199
- IndexMode .LOGSDB ,
200
- false
201
- );
202
-
203
- private static final SourceFieldMapper LOGSDB_DEFAULT_NO_RECOVERY_SOURCE_STORED = new SourceFieldMapper (
204
- Mode .STORED ,
205
- Explicit .IMPLICIT_TRUE ,
206
- Strings .EMPTY_ARRAY ,
207
- Strings .EMPTY_ARRAY ,
208
- IndexMode .LOGSDB ,
209
- false
137
+ IndexMode .LOGSDB
210
138
);
211
139
212
140
/*
@@ -218,17 +146,7 @@ public enum Mode {
218
146
Explicit .IMPLICIT_TRUE ,
219
147
Strings .EMPTY_ARRAY ,
220
148
Strings .EMPTY_ARRAY ,
221
- IndexMode .TIME_SERIES ,
222
- true
223
- );
224
-
225
- private static final SourceFieldMapper TSDB_LEGACY_DEFAULT_NO_RECOVERY_SOURCE = new SourceFieldMapper (
226
- null ,
227
- Explicit .IMPLICIT_TRUE ,
228
- Strings .EMPTY_ARRAY ,
229
- Strings .EMPTY_ARRAY ,
230
- IndexMode .TIME_SERIES ,
231
- false
149
+ IndexMode .TIME_SERIES
232
150
);
233
151
234
152
public static class Defaults {
@@ -289,20 +207,12 @@ public static class Builder extends MetadataFieldMapper.Builder {
289
207
290
208
private final boolean supportsNonDefaultParameterValues ;
291
209
292
- private final boolean enableRecoverySource ;
293
-
294
- public Builder (
295
- IndexMode indexMode ,
296
- final Settings settings ,
297
- boolean supportsCheckForNonDefaultParams ,
298
- boolean enableRecoverySource
299
- ) {
210
+ public Builder (IndexMode indexMode , final Settings settings , boolean supportsCheckForNonDefaultParams ) {
300
211
super (Defaults .NAME );
301
212
this .settings = settings ;
302
213
this .indexMode = indexMode ;
303
214
this .supportsNonDefaultParameterValues = supportsCheckForNonDefaultParams == false
304
215
|| settings .getAsBoolean (LOSSY_PARAMETERS_ALLOWED_SETTING_NAME , true );
305
- this .enableRecoverySource = enableRecoverySource ;
306
216
}
307
217
308
218
public Builder setSynthetic () {
@@ -337,7 +247,7 @@ public SourceFieldMapper build() {
337
247
? INDEX_MAPPER_SOURCE_MODE_SETTING .get (settings )
338
248
: mode .get ();
339
249
if (isDefault (sourceMode )) {
340
- return resolveSourceMode (indexMode , sourceMode == null ? Mode .STORED : sourceMode , enableRecoverySource );
250
+ return resolveSourceMode (indexMode , sourceMode == null ? Mode .STORED : sourceMode );
341
251
342
252
}
343
253
if (supportsNonDefaultParameterValues == false ) {
@@ -368,8 +278,7 @@ public SourceFieldMapper build() {
368
278
enabled .get (),
369
279
includes .getValue ().toArray (Strings .EMPTY_ARRAY ),
370
280
excludes .getValue ().toArray (Strings .EMPTY_ARRAY ),
371
- indexMode ,
372
- enableRecoverySource
281
+ indexMode
373
282
);
374
283
if (indexMode != null ) {
375
284
indexMode .validateSourceFieldMapper (sourceFieldMapper );
@@ -379,32 +288,26 @@ public SourceFieldMapper build() {
379
288
380
289
}
381
290
382
- private static SourceFieldMapper resolveSourceMode (final IndexMode indexMode , final Mode sourceMode , boolean enableRecoverySource ) {
291
+ private static SourceFieldMapper resolveSourceMode (final IndexMode indexMode , final Mode sourceMode ) {
383
292
switch (indexMode ) {
384
293
case STANDARD :
385
294
switch (sourceMode ) {
386
295
case SYNTHETIC :
387
- return enableRecoverySource ? DEFAULT_SYNTHETIC : DEFAULT_SYNTHETIC_NO_RECOVERY_SOURCE ;
296
+ return DEFAULT_SYNTHETIC ;
388
297
case STORED :
389
- return enableRecoverySource ? DEFAULT : DEFAULT_NO_RECOVERY_SOURCE ;
298
+ return DEFAULT ;
390
299
case DISABLED :
391
- return enableRecoverySource ? DEFAULT_DISABLED : DEFAULT_DISABLED_NO_RECOVERY_SOURCE ;
300
+ return DEFAULT_DISABLED ;
392
301
default :
393
302
throw new IllegalArgumentException ("Unsupported source mode: " + sourceMode );
394
303
}
395
304
case TIME_SERIES :
396
305
case LOGSDB :
397
306
switch (sourceMode ) {
398
307
case SYNTHETIC :
399
- return enableRecoverySource
400
- ? (indexMode == IndexMode .TIME_SERIES ? TSDB_DEFAULT : LOGSDB_DEFAULT )
401
- : (indexMode == IndexMode .TIME_SERIES ? TSDB_DEFAULT_NO_RECOVERY_SOURCE : LOGSDB_DEFAULT_NO_RECOVERY_SOURCE );
308
+ return indexMode == IndexMode .TIME_SERIES ? TSDB_DEFAULT : LOGSDB_DEFAULT ;
402
309
case STORED :
403
- return enableRecoverySource
404
- ? (indexMode == IndexMode .TIME_SERIES ? TSDB_DEFAULT_STORED : LOGSDB_DEFAULT_STORED )
405
- : (indexMode == IndexMode .TIME_SERIES
406
- ? TSDB_DEFAULT_NO_RECOVERY_SOURCE_STORED
407
- : LOGSDB_DEFAULT_NO_RECOVERY_SOURCE_STORED );
310
+ return indexMode == IndexMode .TIME_SERIES ? TSDB_DEFAULT_STORED : LOGSDB_DEFAULT_STORED ;
408
311
case DISABLED :
409
312
throw new IllegalArgumentException ("_source can not be disabled in index using [" + indexMode + "] index mode" );
410
313
default :
@@ -417,21 +320,19 @@ private static SourceFieldMapper resolveSourceMode(final IndexMode indexMode, fi
417
320
418
321
public static final TypeParser PARSER = new ConfigurableTypeParser (c -> {
419
322
final IndexMode indexMode = c .getIndexSettings ().getMode ();
420
- boolean enableRecoverySource = INDICES_RECOVERY_SOURCE_ENABLED_SETTING .get (c .getSettings ());
421
323
final Mode settingSourceMode = INDEX_MAPPER_SOURCE_MODE_SETTING .get (c .getSettings ());
422
324
423
325
if (indexMode .isSyntheticSourceEnabled ()) {
424
326
if (indexMode == IndexMode .TIME_SERIES && c .getIndexSettings ().getIndexVersionCreated ().before (IndexVersions .V_8_7_0 )) {
425
- return enableRecoverySource ? TSDB_LEGACY_DEFAULT : TSDB_LEGACY_DEFAULT_NO_RECOVERY_SOURCE ;
327
+ return TSDB_LEGACY_DEFAULT ;
426
328
}
427
329
}
428
- return resolveSourceMode (indexMode , settingSourceMode == null ? Mode .STORED : settingSourceMode , enableRecoverySource );
330
+ return resolveSourceMode (indexMode , settingSourceMode == null ? Mode .STORED : settingSourceMode );
429
331
},
430
332
c -> new Builder (
431
333
c .getIndexSettings ().getMode (),
432
334
c .getSettings (),
433
- c .indexVersionCreated ().onOrAfter (IndexVersions .SOURCE_MAPPER_LOSSY_PARAMS_CHECK ),
434
- INDICES_RECOVERY_SOURCE_ENABLED_SETTING .get (c .getSettings ())
335
+ c .indexVersionCreated ().onOrAfter (IndexVersions .SOURCE_MAPPER_LOSSY_PARAMS_CHECK )
435
336
)
436
337
);
437
338
@@ -484,16 +385,8 @@ public BlockLoader blockLoader(BlockLoaderContext blContext) {
484
385
private final SourceFilter sourceFilter ;
485
386
486
387
private final IndexMode indexMode ;
487
- private final boolean enableRecoverySource ;
488
-
489
- private SourceFieldMapper (
490
- Mode mode ,
491
- Explicit <Boolean > enabled ,
492
- String [] includes ,
493
- String [] excludes ,
494
- IndexMode indexMode ,
495
- boolean enableRecoverySource
496
- ) {
388
+
389
+ private SourceFieldMapper (Mode mode , Explicit <Boolean > enabled , String [] includes , String [] excludes , IndexMode indexMode ) {
497
390
super (new SourceFieldType ((enabled .explicit () && enabled .value ()) || (enabled .explicit () == false && mode != Mode .DISABLED )));
498
391
assert enabled .explicit () == false || mode == null ;
499
392
this .mode = mode ;
@@ -506,7 +399,6 @@ private SourceFieldMapper(
506
399
}
507
400
this .complete = stored () && sourceFilter == null ;
508
401
this .indexMode = indexMode ;
509
- this .enableRecoverySource = enableRecoverySource ;
510
402
}
511
403
512
404
private static SourceFilter buildSourceFilter (String [] includes , String [] excludes ) {
@@ -551,6 +443,7 @@ public void preParse(DocumentParserContext context) throws IOException {
551
443
context .doc ().add (new StoredField (fieldType ().name (), ref .bytes , ref .offset , ref .length ));
552
444
}
553
445
446
+ boolean enableRecoverySource = context .indexSettings ().isRecoverySourceEnabled ();
554
447
if (enableRecoverySource && originalSource != null && adaptedSource != originalSource ) {
555
448
// if we omitted source or modified it we add the _recovery_source to ensure we have it for ops based recovery
556
449
BytesRef ref = originalSource .toBytesRef ();
@@ -579,7 +472,7 @@ protected String contentType() {
579
472
580
473
@ Override
581
474
public FieldMapper .Builder getMergeBuilder () {
582
- return new Builder (indexMode , Settings .EMPTY , false , enableRecoverySource ).init (this );
475
+ return new Builder (indexMode , Settings .EMPTY , false ).init (this );
583
476
}
584
477
585
478
/**
0 commit comments