public Builder dynamicDateTimeFormatter(Iterable<FormatDateTimeFormatter> dateTimeFormatters) {
   for (FormatDateTimeFormatter dateTimeFormatter : dateTimeFormatters) {
     if (!seenDateFormats.contains(dateTimeFormatter.format())) {
       seenDateFormats.add(dateTimeFormatter.format());
       this.dynamicDateTimeFormatters.add(dateTimeFormatter);
     }
   }
   return builder;
 }
  @Override
  protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    if (dynamicDateTimeFormatters != Defaults.DYNAMIC_DATE_TIME_FORMATTERS) {
      if (dynamicDateTimeFormatters.length > 0) {
        builder.startArray("dynamic_date_formats");
        for (FormatDateTimeFormatter dateTimeFormatter : dynamicDateTimeFormatters) {
          builder.value(dateTimeFormatter.format());
        }
        builder.endArray();
      }
    }

    if (dynamicTemplates != null && dynamicTemplates.length > 0) {
      builder.startArray("dynamic_templates");
      for (DynamicTemplate dynamicTemplate : dynamicTemplates) {
        builder.startObject();
        builder.field(dynamicTemplate.name());
        builder.map(dynamicTemplate.conf());
        builder.endObject();
      }
      builder.endArray();
    }

    if (dateDetection != Defaults.DATE_DETECTION) {
      builder.field("date_detection", dateDetection);
    }
    if (numericDetection != Defaults.NUMERIC_DETECTION) {
      builder.field("numeric_detection", numericDetection);
    }
  }
  @Override
  protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params)
      throws IOException {
    super.doXContentBody(builder, includeDefaults, params);

    if (includeDefaults || precisionStep != Defaults.PRECISION_STEP_64_BIT) {
      builder.field("precision_step", precisionStep);
    }
    builder.field("format", dateTimeFormatter.format());
    if (includeDefaults || nullValue != null) {
      builder.field("null_value", nullValue);
    }
    if (includeInAll != null) {
      builder.field("include_in_all", includeInAll);
    } else if (includeDefaults) {
      builder.field("include_in_all", false);
    }

    if (includeDefaults || timeUnit != Defaults.TIME_UNIT) {
      builder.field("numeric_resolution", timeUnit.name().toLowerCase(Locale.ROOT));
    }
    // only serialize locale if needed, ROOT is the default, so no need to serialize that case as
    // well...
    if (dateTimeFormatter.locale() != null && dateTimeFormatter.locale() != Locale.ROOT) {
      builder.field("locale", dateTimeFormatter.locale());
    } else if (includeDefaults) {
      if (dateTimeFormatter.locale() == null) {
        builder.field("locale", Locale.ROOT);
      } else {
        builder.field("locale", dateTimeFormatter.locale());
      }
    }
  }
 @Override
 public DateFieldMapper build(BuilderContext context) {
   fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
   if (!locale.equals(dateTimeFormatter.locale())) {
     dateTimeFormatter =
         new FormatDateTimeFormatter(
             dateTimeFormatter.format(),
             dateTimeFormatter.parser(),
             dateTimeFormatter.printer(),
             locale);
   }
   DateFieldMapper fieldMapper =
       new DateFieldMapper(
           buildNames(context),
           dateTimeFormatter,
           fieldType.numericPrecisionStep(),
           boost,
           fieldType,
           docValues,
           nullValue,
           timeUnit,
           ignoreMalformed(context),
           coerce(context),
           postingsProvider,
           docValuesProvider,
           similarity,
           normsLoading,
           fieldDataSettings,
           context.indexSettings(),
           multiFieldsBuilder.build(this, context),
           copyTo);
   fieldMapper.includeInAll(includeInAll);
   return fieldMapper;
 }
 private long parseStringValue(String value) {
   try {
     return dateTimeFormatter.parser().parseMillis(value);
   } catch (RuntimeException e) {
     try {
       long time = Long.parseLong(value);
       return timeUnit.toMillis(time);
     } catch (NumberFormatException e1) {
       throw new MapperParsingException(
           "failed to parse date field ["
               + value
               + "], tried both date format ["
               + dateTimeFormatter.format()
               + "], and timestamp number with locale ["
               + dateTimeFormatter.locale()
               + "]",
           e);
     }
   }
 }