Пример #1
0
  @Override
  public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(simpleName());
    builder.field("type", CONTENT_TYPE);
    if (indexCreatedBefore2x) {
      builder.field("path", pathType.name().toLowerCase(Locale.ROOT));
    }

    builder.startObject("fields");
    contentMapper.toXContent(builder, params);
    authorMapper.toXContent(builder, params);
    titleMapper.toXContent(builder, params);
    nameMapper.toXContent(builder, params);
    dateMapper.toXContent(builder, params);
    keywordsMapper.toXContent(builder, params);
    contentTypeMapper.toXContent(builder, params);
    contentLengthMapper.toXContent(builder, params);
    languageMapper.toXContent(builder, params);
    multiFields.toXContent(builder, params);
    builder.endObject();

    multiFields.toXContent(builder, params);
    builder.endObject();
    return builder;
  }
 private void addFieldMapper(
     String field,
     FieldMapper<?> fieldMapper,
     MapBuilder<String, FieldMappingMetaData> fieldMappings,
     boolean includeDefaults) {
   if (fieldMappings.containsKey(field)) {
     return;
   }
   try {
     XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
     builder.startObject();
     fieldMapper.toXContent(
         builder, includeDefaults ? includeDefaultsParams : ToXContent.EMPTY_PARAMS);
     builder.endObject();
     fieldMappings.put(
         field, new FieldMappingMetaData(fieldMapper.names().fullName(), builder.bytes()));
   } catch (IOException e) {
     throw new ElasticsearchException("failed to serialize XContent of field [" + field + "]", e);
   }
 }