コード例 #1
0
  @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);
    }
  }
コード例 #2
0
 @Override
 protected void doMerge(ObjectMapper mergeWith, MergeContext mergeContext) {
   RootObjectMapper mergeWithObject = (RootObjectMapper) mergeWith;
   if (!mergeContext.mergeFlags().simulate()) {
     // merge them
     List<DynamicTemplate> mergedTemplates =
         Lists.newArrayList(Arrays.asList(this.dynamicTemplates));
     for (DynamicTemplate template : mergeWithObject.dynamicTemplates) {
       boolean replaced = false;
       for (int i = 0; i < mergedTemplates.size(); i++) {
         if (mergedTemplates.get(i).name().equals(template.name())) {
           mergedTemplates.set(i, template);
           replaced = true;
         }
       }
       if (!replaced) {
         mergedTemplates.add(template);
       }
     }
     this.dynamicTemplates = mergedTemplates.toArray(new DynamicTemplate[mergedTemplates.size()]);
   }
 }