Search in sources :

Example 1 with ParentChild

use of org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild in project elasticsearch by elastic.

the class ChildrenAggregationBuilder method resolveConfig.

@Override
protected ValuesSourceConfig<ParentChild> resolveConfig(SearchContext context) {
    ValuesSourceConfig<ParentChild> config = new ValuesSourceConfig<>(ValuesSourceType.BYTES);
    DocumentMapper childDocMapper = context.mapperService().documentMapper(childType);
    if (childDocMapper != null) {
        ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
        if (!parentFieldMapper.active()) {
            throw new IllegalArgumentException("[children] no [_parent] field not configured that points to a parent type");
        }
        parentType = parentFieldMapper.type();
        DocumentMapper parentDocMapper = context.mapperService().documentMapper(parentType);
        if (parentDocMapper != null) {
            parentFilter = parentDocMapper.typeFilter();
            childFilter = childDocMapper.typeFilter();
            ParentChildIndexFieldData parentChildIndexFieldData = context.fieldData().getForField(parentFieldMapper.fieldType());
            config.fieldContext(new FieldContext(parentFieldMapper.fieldType().name(), parentChildIndexFieldData, parentFieldMapper.fieldType()));
        } else {
            config.unmapped(true);
        }
    } else {
        config.unmapped(true);
    }
    return config;
}
Also used : ParentFieldMapper(org.elasticsearch.index.mapper.ParentFieldMapper) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) ValuesSourceConfig(org.elasticsearch.search.aggregations.support.ValuesSourceConfig) FieldContext(org.elasticsearch.search.aggregations.support.FieldContext) ParentChildIndexFieldData(org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData) ParentChild(org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild)

Aggregations

ParentChildIndexFieldData (org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData)1 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)1 ParentFieldMapper (org.elasticsearch.index.mapper.ParentFieldMapper)1 FieldContext (org.elasticsearch.search.aggregations.support.FieldContext)1 ParentChild (org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild)1 ValuesSourceConfig (org.elasticsearch.search.aggregations.support.ValuesSourceConfig)1