3838import org .elasticsearch .features .NodeFeature ;
3939import org .elasticsearch .index .IndexMode ;
4040import org .elasticsearch .index .IndexSettings ;
41- import org .elasticsearch .index .IndexSortConfig ;
4241import org .elasticsearch .index .IndexVersion ;
4342import org .elasticsearch .index .IndexVersions ;
4443import org .elasticsearch .index .fielddata .FieldDataContext ;
@@ -287,47 +286,25 @@ public static final class Builder extends FieldMapper.Builder {
287286 private final Resolution resolution ;
288287 private final IndexVersion indexCreatedVersion ;
289288 private final ScriptCompiler scriptCompiler ;
290- private final IndexMode indexMode ;
291- private final IndexSortConfig indexSortConfig ;
292- private final boolean useDocValuesSkipper ;
289+ private final IndexSettings indexSettings ;
293290
294291 public Builder (
295292 String name ,
296293 Resolution resolution ,
297294 DateFormatter dateFormatter ,
298295 ScriptCompiler scriptCompiler ,
299- boolean ignoreMalformedByDefault ,
300- IndexVersion indexCreatedVersion
301- ) {
302- this (
303- name ,
304- resolution ,
305- dateFormatter ,
306- scriptCompiler ,
307- ignoreMalformedByDefault ,
308- IndexMode .STANDARD ,
309- null ,
310- indexCreatedVersion ,
311- false
312- );
313- }
314-
315- public Builder (
316- String name ,
317- Resolution resolution ,
318- DateFormatter dateFormatter ,
319- ScriptCompiler scriptCompiler ,
320- boolean ignoreMalformedByDefault ,
321- IndexMode indexMode ,
322- IndexSortConfig indexSortConfig ,
323- IndexVersion indexCreatedVersion ,
324- boolean useDocValuesSkipper
296+ IndexSettings indexSettings
325297 ) {
326298 super (name );
327299 this .resolution = resolution ;
328- this .indexCreatedVersion = indexCreatedVersion ;
300+ this .indexCreatedVersion = indexSettings . getIndexVersionCreated () ;
329301 this .scriptCompiler = Objects .requireNonNull (scriptCompiler );
330- this .ignoreMalformed = Parameter .boolParam ("ignore_malformed" , true , m -> toType (m ).ignoreMalformed , ignoreMalformedByDefault );
302+ this .ignoreMalformed = Parameter .boolParam (
303+ "ignore_malformed" ,
304+ true ,
305+ m -> toType (m ).ignoreMalformed ,
306+ FieldMapper .IGNORE_MALFORMED_SETTING .get (indexSettings .getSettings ())
307+ );
331308
332309 this .script .precludesParameters (nullValue , ignoreMalformed );
333310 addScriptValidation (script , index , docValues );
@@ -345,9 +322,12 @@ public Builder(
345322 this .format .setValue (dateFormatter .pattern ());
346323 this .locale .setValue (dateFormatter .locale ());
347324 }
348- this .indexMode = indexMode ;
349- this .indexSortConfig = indexSortConfig ;
350- this .useDocValuesSkipper = useDocValuesSkipper ;
325+ this .indexSettings = indexSettings ;
326+ }
327+
328+ public Builder ignoreMalformed (boolean ignoreMalformed ) {
329+ this .ignoreMalformed .setValue (ignoreMalformed );
330+ return this ;
351331 }
352332
353333 DateFormatter buildFormatter () {
@@ -419,14 +399,7 @@ private Long parseNullValue(DateFieldType fieldType) {
419399 }
420400
421401 private IndexType indexType (String fullFieldName ) {
422- boolean hasDocValuesSkipper = shouldUseDocValuesSkipper (
423- indexCreatedVersion ,
424- useDocValuesSkipper ,
425- docValues .getValue (),
426- indexMode ,
427- indexSortConfig ,
428- fullFieldName
429- );
402+ boolean hasDocValuesSkipper = shouldUseDocValuesSkipper (indexSettings , docValues .getValue (), fullFieldName );
430403 if (hasDocValuesSkipper ) {
431404 return IndexType .skippers ();
432405 }
@@ -467,42 +440,17 @@ public DateFieldMapper build(MapperBuilderContext context) {
467440 nullTimestamp ,
468441 resolution ,
469442 context .isSourceSynthetic (),
470- indexMode ,
471- indexSortConfig ,
472- indexType .hasDocValuesSkipper (),
473443 this
474444 );
475445 }
476446 }
477447
478448 public static final TypeParser MILLIS_PARSER = createTypeParserWithLegacySupport ((n , c ) -> {
479- boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING .get (c .getSettings ());
480- return new Builder (
481- n ,
482- Resolution .MILLISECONDS ,
483- c .getDateFormatter (),
484- c .scriptCompiler (),
485- ignoreMalformedByDefault ,
486- c .getIndexSettings ().getMode (),
487- c .getIndexSettings ().getIndexSortConfig (),
488- c .indexVersionCreated (),
489- IndexSettings .USE_DOC_VALUES_SKIPPER .get (c .getSettings ())
490- );
449+ return new Builder (n , Resolution .MILLISECONDS , c .getDateFormatter (), c .scriptCompiler (), c .getIndexSettings ());
491450 });
492451
493452 public static final TypeParser NANOS_PARSER = createTypeParserWithLegacySupport ((n , c ) -> {
494- boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING .get (c .getSettings ());
495- return new Builder (
496- n ,
497- Resolution .NANOSECONDS ,
498- c .getDateFormatter (),
499- c .scriptCompiler (),
500- ignoreMalformedByDefault ,
501- c .getIndexSettings ().getMode (),
502- c .getIndexSettings ().getIndexSortConfig (),
503- c .indexVersionCreated (),
504- IndexSettings .USE_DOC_VALUES_SKIPPER .get (c .getSettings ())
505- );
453+ return new Builder (n , Resolution .NANOSECONDS , c .getDateFormatter (), c .scriptCompiler (), c .getIndexSettings ());
506454 });
507455
508456 public static final class DateFieldType extends MappedFieldType {
@@ -1114,17 +1062,12 @@ public DocValueFormat docValueFormat(@Nullable String format, ZoneId timeZone) {
11141062 private final Resolution resolution ;
11151063 private final boolean isSourceSynthetic ;
11161064
1117- private final boolean ignoreMalformedByDefault ;
1118- private final IndexVersion indexCreatedVersion ;
1119-
11201065 private final Script script ;
11211066 private final ScriptCompiler scriptCompiler ;
11221067 private final FieldValues <Long > scriptValues ;
11231068
11241069 private final boolean isDataStreamTimestampField ;
1125- private final IndexMode indexMode ;
1126- private final IndexSortConfig indexSortConfig ;
1127- private final boolean hasDocValuesSkipper ;
1070+ private final IndexSettings indexSettings ;
11281071
11291072 private DateFieldMapper (
11301073 String leafName ,
@@ -1133,9 +1076,6 @@ private DateFieldMapper(
11331076 Long nullValue ,
11341077 Resolution resolution ,
11351078 boolean isSourceSynthetic ,
1136- IndexMode indexMode ,
1137- IndexSortConfig indexSortConfig ,
1138- boolean hasDocValuesSkipper ,
11391079 Builder builder
11401080 ) {
11411081 super (leafName , mappedFieldType , builderParams );
@@ -1149,15 +1089,11 @@ private DateFieldMapper(
11491089 this .nullValue = nullValue ;
11501090 this .resolution = resolution ;
11511091 this .isSourceSynthetic = isSourceSynthetic ;
1152- this .ignoreMalformedByDefault = builder .ignoreMalformed .getDefaultValue ();
1153- this .indexCreatedVersion = builder .indexCreatedVersion ;
11541092 this .script = builder .script .get ();
11551093 this .scriptCompiler = builder .scriptCompiler ;
11561094 this .scriptValues = builder .scriptValues ();
11571095 this .isDataStreamTimestampField = mappedFieldType .name ().equals (DataStreamTimestampFieldMapper .DEFAULT_PATH );
1158- this .indexMode = indexMode ;
1159- this .indexSortConfig = indexSortConfig ;
1160- this .hasDocValuesSkipper = hasDocValuesSkipper ;
1096+ this .indexSettings = builder .indexSettings ;
11611097 }
11621098
11631099 /**
@@ -1168,46 +1104,25 @@ private DateFieldMapper(
11681104 * field has doc values enabled. Additionally, the index mode must be {@link IndexMode#LOGSDB} or {@link IndexMode#TIME_SERIES}, and
11691105 * the index sorting configuration must include the {@code @timestamp} field.
11701106 *
1171- * @param indexCreatedVersion The version of the index when it was created.
1172- * @param useDocValuesSkipper Whether the doc values skipper feature is enabled via the {@code index.mapping.use_doc_values_skipper}
1173- * setting.
1174- * @param hasDocValues Whether the field has doc values enabled.
1175- * @param indexMode The index mode, which must be {@link IndexMode#LOGSDB} or {@link IndexMode#TIME_SERIES}.
1176- * @param indexSortConfig The index sorting configuration, which must include the {@code @timestamp} field.
1177- * @param fullFieldName The full name of the field being checked, expected to be {@code @timestamp}.
1107+ * @param indexSettings The index settings of the parent index
1108+ * @param hasDocValues Whether the field has doc values enabled.
1109+ * @param fullFieldName The full name of the field being checked, expected to be {@code @timestamp}.
11781110 * @return {@code true} if the doc values skipper should be used, {@code false} otherwise.
11791111 */
11801112
1181- private static boolean shouldUseDocValuesSkipper (
1182- final IndexVersion indexCreatedVersion ,
1183- boolean useDocValuesSkipper ,
1184- boolean hasDocValues ,
1185- final IndexMode indexMode ,
1186- final IndexSortConfig indexSortConfig ,
1187- final String fullFieldName
1188- ) {
1189- return indexCreatedVersion .onOrAfter (IndexVersions .REENABLED_TIMESTAMP_DOC_VALUES_SPARSE_INDEX )
1190- && useDocValuesSkipper
1113+ private static boolean shouldUseDocValuesSkipper (IndexSettings indexSettings , boolean hasDocValues , final String fullFieldName ) {
1114+ return indexSettings .getIndexVersionCreated ().onOrAfter (IndexVersions .REENABLED_TIMESTAMP_DOC_VALUES_SPARSE_INDEX )
1115+ && indexSettings .useDocValuesSkipper ()
11911116 && hasDocValues
1192- && (IndexMode .LOGSDB .equals (indexMode ) || IndexMode .TIME_SERIES .equals (indexMode ))
1193- && indexSortConfig != null
1194- && indexSortConfig .hasSortOnField (fullFieldName )
1117+ && (IndexMode .LOGSDB .equals (indexSettings . getMode ()) || IndexMode .TIME_SERIES .equals (indexSettings . getMode () ))
1118+ && indexSettings . getIndexSortConfig () != null
1119+ && indexSettings . getIndexSortConfig () .hasSortOnField (fullFieldName )
11951120 && DataStreamTimestampFieldMapper .DEFAULT_PATH .equals (fullFieldName );
11961121 }
11971122
11981123 @ Override
11991124 public FieldMapper .Builder getMergeBuilder () {
1200- return new Builder (
1201- leafName (),
1202- resolution ,
1203- null ,
1204- scriptCompiler ,
1205- ignoreMalformedByDefault ,
1206- indexMode ,
1207- indexSortConfig ,
1208- indexCreatedVersion ,
1209- hasDocValuesSkipper
1210- ).init (this );
1125+ return new Builder (leafName (), resolution , null , scriptCompiler , indexSettings ).init (this );
12111126 }
12121127
12131128 @ Override
@@ -1277,7 +1192,7 @@ private void indexValue(DocumentParserContext context, long timestamp) {
12771192 DataStreamTimestampFieldMapper .storeTimestampValueForReuse (context .doc (), timestamp );
12781193 }
12791194
1280- if (hasDocValuesSkipper && hasDocValues ) {
1195+ if (fieldType (). hasDocValuesSkipper () ) {
12811196 context .doc ().add (SortedNumericDocValuesField .indexedField (fieldType ().name (), timestamp ));
12821197 } else if (indexed && hasDocValues ) {
12831198 context .doc ().add (new LongField (fieldType ().name (), timestamp , Field .Store .NO ));
0 commit comments