public static class Builder extends MetadataFieldMapper.Builder<Builder, ParentFieldMapper> { private String parentType; protected String indexName; private final String documentType; private final MappedFieldType parentJoinFieldType = Defaults.JOIN_FIELD_TYPE.clone(); private final MappedFieldType childJoinFieldType = Defaults.JOIN_FIELD_TYPE.clone(); public Builder(String documentType) { super(Defaults.NAME, Defaults.FIELD_TYPE, Defaults.FIELD_TYPE); this.indexName = name; this.documentType = documentType; builder = this; } public Builder type(String type) { this.parentType = type; return builder; } @Override public Builder fieldDataSettings(Settings fieldDataSettings) { Settings settings = Settings.builder() .put(childJoinFieldType.fieldDataType().getSettings()) .put(fieldDataSettings) .build(); childJoinFieldType.setFieldDataType( new FieldDataType(childJoinFieldType.fieldDataType().getType(), settings)); return this; } @Override public ParentFieldMapper build(BuilderContext context) { if (parentType == null) { throw new MapperParsingException("[_parent] field mapping must contain the [type] option"); } parentJoinFieldType.setName(joinField(documentType)); parentJoinFieldType.setFieldDataType(null); childJoinFieldType.setName(joinField(parentType)); return new ParentFieldMapper( fieldType, parentJoinFieldType, childJoinFieldType, parentType, context.indexSettings()); } }
private static MappedFieldType joinFieldTypeForParentType( String parentType, Settings indexSettings) { MappedFieldType parentJoinFieldType = Defaults.JOIN_FIELD_TYPE.clone(); parentJoinFieldType.setName(joinField(parentType)); parentJoinFieldType.freeze(); return parentJoinFieldType; }
private boolean joinFieldHasCustomFieldDataSettings() { return childJoinFieldType != null && childJoinFieldType.fieldDataType() != null && childJoinFieldType.fieldDataType().equals(Defaults.JOIN_FIELD_TYPE.fieldDataType()) == false; }