Пример #1
0
 protected boolean processField(
     ObjectMapper.Builder builder, String fieldName, Object fieldNode) {
   if (fieldName.equals("date_formats") || fieldName.equals("dynamic_date_formats")) {
     List<FormatDateTimeFormatter> dateTimeFormatters = newArrayList();
     if (fieldNode instanceof List) {
       for (Object node1 : (List) fieldNode) {
         dateTimeFormatters.add(parseDateTimeFormatter(fieldName, node1));
       }
     } else if ("none".equals(fieldNode.toString())) {
       dateTimeFormatters = null;
     } else {
       dateTimeFormatters.add(parseDateTimeFormatter(fieldName, fieldNode));
     }
     if (dateTimeFormatters == null) {
       ((Builder) builder).noDynamicDateTimeFormatter();
     } else {
       ((Builder) builder).dynamicDateTimeFormatter(dateTimeFormatters);
     }
     return true;
   } else if (fieldName.equals("dynamic_templates")) {
     //  "dynamic_templates" : [
     //      {
     //          "template_1" : {
     //              "match" : "*_test",
     //              "match_mapping_type" : "string",
     //              "mapping" : { "type" : "string", "store" : "yes" }
     //          }
     //      }
     //  ]
     List tmplNodes = (List) fieldNode;
     for (Object tmplNode : tmplNodes) {
       Map<String, Object> tmpl = (Map<String, Object>) tmplNode;
       if (tmpl.size() != 1) {
         throw new MapperParsingException("A dynamic template must be defined with a name");
       }
       Map.Entry<String, Object> entry = tmpl.entrySet().iterator().next();
       ((Builder) builder)
           .add(DynamicTemplate.parse(entry.getKey(), (Map<String, Object>) entry.getValue()));
     }
     return true;
   } else if (fieldName.equals("date_detection")) {
     ((Builder) builder).dateDetection = nodeBooleanValue(fieldNode);
     return true;
   } else if (fieldName.equals("numeric_detection")) {
     ((Builder) builder).numericDetection = nodeBooleanValue(fieldNode);
     return true;
   }
   return false;
 }