Java Code Examples for org.elasticsearch.search.aggregations.support.ValuesSourceConfig#unmapped()

The following examples show how to use org.elasticsearch.search.aggregations.support.ValuesSourceConfig#unmapped() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignificantTermsAggregatorFactory.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public SignificantTermsAggregatorFactory(String name, ValuesSourceConfig valueSourceConfig, TermsAggregator.BucketCountThresholds bucketCountThresholds, IncludeExclude includeExclude,
                                         String executionHint, Query filter, SignificanceHeuristic significanceHeuristic) {

    super(name, SignificantStringTerms.TYPE.name(), valueSourceConfig);
    this.bucketCountThresholds = bucketCountThresholds;
    this.includeExclude = includeExclude;
    this.executionHint = executionHint;
    this.significanceHeuristic = significanceHeuristic;
    if (!valueSourceConfig.unmapped()) {
        this.indexedFieldName = config.fieldContext().field();
        fieldType = SearchContext.current().smartNameFieldType(indexedFieldName);
    }
    this.filter = filter;
}
 
Example 2
Source File: ChildrenParser.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    String childType = null;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("type".equals(currentFieldName)) {
                childType = parser.text();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    if (childType == null) {
        throw new SearchParseException(context, "Missing [child_type] field for children aggregation [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    ValuesSourceConfig<ValuesSource.Bytes.WithOrdinals.ParentChild> config = new ValuesSourceConfig<>(ValuesSource.Bytes.WithOrdinals.ParentChild.class);
    DocumentMapper childDocMapper = context.mapperService().documentMapper(childType);

    String parentType = null;
    Query parentFilter = null;
    Query childFilter = null;
    if (childDocMapper != null) {
        ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
        if (!parentFieldMapper.active()) {
            throw new SearchParseException(context, "[children] no [_parent] field not configured that points to a parent type", parser.getTokenLocation());
        }
        parentType = parentFieldMapper.type();
        DocumentMapper parentDocMapper = context.mapperService().documentMapper(parentType);
        if (parentDocMapper != null) {
            // TODO: use the query API
            parentFilter = parentDocMapper.typeFilter();
            childFilter = childDocMapper.typeFilter();
            ParentChildIndexFieldData parentChildIndexFieldData = context.fieldData().getForField(parentFieldMapper.fieldType());
            config.fieldContext(new FieldContext(parentFieldMapper.fieldType().names().indexName(), parentChildIndexFieldData, parentFieldMapper.fieldType()));
        } else {
            config.unmapped(true);
        }
    } else {
        config.unmapped(true);
    }
    return new ParentToChildrenAggregator.Factory(aggregationName, config, parentType, parentFilter, childFilter);
}
 
Example 3
Source File: TopKParser.java    From elasticsearch-topk-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceConfig<ValuesSource.Bytes> config = new ValuesSourceConfig<>(ValuesSource.Bytes.class);
    
    String field = null;
    Number size = null;
    Number capacity = 1000;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("field".equals(currentFieldName)) {
                field = parser.text();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else if (token == XContentParser.Token.VALUE_NUMBER) {
            if ("size".equals(currentFieldName)) {
                size = parser.numberValue();
            } else if ("capacity".equals(currentFieldName)) {
                    capacity = parser.numberValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].");
        }
    }

    if (field == null) {
        throw new SearchParseException(context, "Key 'field' cannot be null.");
    }
    if (size == null) {
        throw new SearchParseException(context, "Key 'size' cannot be null.");
    }

    FieldMapper<?> mapper = context.smartNameFieldMapper(field);
    if (mapper == null) {
        config.unmapped(true);
        return new TopKAggregator.Factory(aggregationName, config, size, capacity);
    }
    config.fieldContext(new FieldContext(field, context.fieldData().getForField(mapper), mapper));
    return new TopKAggregator.Factory(aggregationName, config, size, capacity);
}