@Override
    public Y build(BuilderContext context) {
      ContentPath.Type origPathType = context.path().pathType();
      context.path().pathType(pathType);
      context.path().add(name);

      Map<String, Mapper> mappers = new HashMap<String, Mapper>();
      for (Mapper.Builder builder : mappersBuilders) {
        Mapper mapper = builder.build(context);
        mappers.put(mapper.name(), mapper);
      }
      context.path().pathType(origPathType);
      context.path().remove();

      ObjectMapper objectMapper =
          createMapper(
              name,
              context.path().fullPathAsText(name),
              enabled,
              nested,
              dynamic,
              pathType,
              mappers);
      objectMapper.includeInAllIfNotSet(includeInAll);

      return (Y) objectMapper;
    }
    @Override
    public AttachmentMapper build(BuilderContext context) {
      ContentPath.Type origPathType = context.path().pathType();
      context.path().pathType(pathType);

      FieldMapper contentMapper;
      if (context.indexCreatedVersion().before(Version.V_2_0_0_beta1)) {
        // old behavior, we need the content to be indexed under the attachment field name
        if (contentBuilder instanceof FieldMapper.Builder == false) {
          throw new IllegalStateException("content field for attachment must be a field mapper");
        }
        ((FieldMapper.Builder) contentBuilder).indexName(name);
        contentBuilder.name = name + "." + FieldNames.CONTENT;
        contentMapper = (FieldMapper) contentBuilder.build(context);
        context.path().add(name);
      } else {
        context.path().add(name);
        contentMapper = (FieldMapper) contentBuilder.build(context);
      }

      FieldMapper dateMapper = (FieldMapper) dateBuilder.build(context);
      FieldMapper authorMapper = (FieldMapper) authorBuilder.build(context);
      FieldMapper titleMapper = (FieldMapper) titleBuilder.build(context);
      FieldMapper nameMapper = (FieldMapper) nameBuilder.build(context);
      FieldMapper keywordsMapper = (FieldMapper) keywordsBuilder.build(context);
      FieldMapper contentTypeMapper = (FieldMapper) contentTypeBuilder.build(context);
      FieldMapper contentLength = (FieldMapper) contentLengthBuilder.build(context);
      FieldMapper language = (FieldMapper) languageBuilder.build(context);
      context.path().remove();

      context.path().pathType(origPathType);

      if (defaultIndexedChars == null && context.indexSettings() != null) {
        defaultIndexedChars =
            context.indexSettings().getAsInt("index.mapping.attachment.indexed_chars", 100000);
      }
      if (defaultIndexedChars == null) {
        defaultIndexedChars = 100000;
      }

      if (ignoreErrors == null && context.indexSettings() != null) {
        ignoreErrors =
            context
                .indexSettings()
                .getAsBoolean("index.mapping.attachment.ignore_errors", Boolean.TRUE);
      }
      if (ignoreErrors == null) {
        ignoreErrors = Boolean.TRUE;
      }

      if (langDetect == null && context.indexSettings() != null) {
        langDetect =
            context
                .indexSettings()
                .getAsBoolean("index.mapping.attachment.detect_language", Boolean.FALSE);
      }
      if (langDetect == null) {
        langDetect = Boolean.FALSE;
      }
      MappedFieldType defaultFieldType = Defaults.FIELD_TYPE.clone();
      if (this.fieldType.indexOptions() != IndexOptions.NONE && !this.fieldType.tokenized()) {
        defaultFieldType.setOmitNorms(true);
        defaultFieldType.setIndexOptions(IndexOptions.DOCS);
        if (!this.omitNormsSet && this.fieldType.boost() == 1.0F) {
          this.fieldType.setOmitNorms(true);
        }

        if (!this.indexOptionsSet) {
          this.fieldType.setIndexOptions(IndexOptions.DOCS);
        }
      }

      defaultFieldType.freeze();
      this.setupFieldType(context);
      return new AttachmentMapper(
          name,
          fieldType,
          defaultFieldType,
          pathType,
          defaultIndexedChars,
          ignoreErrors,
          langDetect,
          contentMapper,
          dateMapper,
          titleMapper,
          nameMapper,
          authorMapper,
          keywordsMapper,
          contentTypeMapper,
          contentLength,
          language,
          context.indexSettings(),
          multiFieldsBuilder.build(this, context),
          copyTo);
    }