Java源码示例:org.elasticsearch.search.aggregations.support.ValueType

示例1
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    ValuesSourceParser<ValuesSource.GeoPoint> vsParser = ValuesSourceParser.geoPoint(aggregationName, InternalGeoCentroid.TYPE, context)
            .targetValueType(ValueType.GEOPOINT)
            .formattable(true)
            .build();
    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 (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else {
            throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                    + currentFieldName + "].", parser.getTokenLocation());
        }
    }
    return new GeoCentroidAggregator.Factory(aggregationName, vsParser.config());
}
 
示例2
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    ValuesSourceParser<GeoPoint> vsParser = ValuesSourceParser.geoPoint(aggregationName, InternalGeoBounds.TYPE, context)
            .targetValueType(ValueType.GEOPOINT)
            .formattable(true)
            .build();
    boolean wrapLongitude = true;
    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 (vsParser.token(currentFieldName, token, parser)) {
            continue;
            
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("wrap_longitude".equals(currentFieldName) || "wrapLongitude".equals(currentFieldName)) {
                wrapLongitude = parser.booleanValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                    + currentFieldName + "].", parser.getTokenLocation());
        }
    }
    return new GeoBoundsAggregator.Factory(aggregationName, vsParser.config(), wrapLongitude);
}
 
示例3
@Override
protected B createFactory(final String aggregationName,
    final ValuesSourceType valuesSourceType,
    final ValueType targetValueType, final Map<ParseField, Object> otherOptions) {
  final B builder = createInnerFactory(aggregationName, otherOptions);
  final String mode = (String) otherOptions.get(MULTIVALUE_MODE_FIELD);
  if (mode != null) {
    builder.multiValueMode(MultiValueMode.fromString(mode));
  }
  return builder;
}
 
示例4
/**
 * Read from a stream.
 */
public GeoPointClusteringAggregationBuilder(StreamInput in) throws IOException {
    super(in, CoreValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
    zoom = in.readInt();
    radius = in.readInt();
    extent = in.readInt();
    ratio = in.readDouble();
    requiredSize = in.readVInt();
    shardSize = in.readVInt();
}
 
示例5
/**
 * Produces a list of all unique values for a given field in a collection.
 *
 * @param collection The collection that will be queried.
 * @param path The request path containing property fieldsExtension and values for which to find unique values
 * @return A list of unique values
 */
@Override
public List<String> getValuesForField(CollectionMetadata collection, List<String> path) {
    String fieldName = path.get(path.size() - 1);

    List<String> values = new LinkedList<>();
    fieldName = "properties." + fieldName;

    // build the term aggregation from the last subcatalog property in the url path
    TermsAggregationBuilder aggregationBuilder = new TermsAggregationBuilder(fieldName + "_Agg", ValueType.STRING).size(10000);
    aggregationBuilder.field(fieldName);

    // the query based on all of the unique subcatalog value previously selected
    QueryBuilder query = QueryBuilders.boolQuery();
    for (int i = 2; i * 2 <= path.size(); i = i + 2) {
        String property = "properties." + path.get(i);
        String value = path.get(i + 1);
        QueryBuilder pathQuery = QueryBuilders.termQuery(property, value);

        ((BoolQueryBuilder) query).must(pathQuery);
    }

    SearchRequest request = new SearchRequest().indices(indexAliasLookup.getReadAlias(collection.getId()))
            .searchType(SearchType.DFS_QUERY_THEN_FETCH)
            .source(new SearchSourceBuilder().query(query).aggregation(aggregationBuilder).size(0));

    SearchResponse response;
    try {
        response = client.search(request, RequestOptions.DEFAULT);
    } catch (Exception ex) {
        log.error("Error getting aggregations.", ex);
        throw new RuntimeException("Error getting aggregations.", ex);
    }

    if (response == null) return Collections.EMPTY_LIST;

    ParsedTerms terms = response.getAggregations().get(fieldName + "_Agg");
    if (terms != null) {
        List<ParsedTerms.ParsedBucket> buckets = (List<ParsedTerms.ParsedBucket>) terms.getBuckets();
        if (buckets != null && buckets.size() > 0) {
            for (ParsedTerms.ParsedBucket bucket : buckets) {
                values.add(bucket.getKeyAsString());
            }
        }
        return values;
    }
    return Collections.EMPTY_LIST;
}
 
示例6
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser<ValuesSource.Numeric> vsParser = ValuesSourceParser.numeric(aggregationName, InternalIPv4Range.TYPE, context)
            .targetValueType(ValueType.IP)
            .formattable(false)
            .build();

    List<RangeAggregator.Range> ranges = null;
    boolean keyed = false;

    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 (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else if (token == XContentParser.Token.START_ARRAY) {
            if ("ranges".equals(currentFieldName)) {
                ranges = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    double from = Double.NEGATIVE_INFINITY;
                    String fromAsStr = null;
                    double to = Double.POSITIVE_INFINITY;
                    String toAsStr = null;
                    String key = null;
                    String mask = null;
                    String toOrFromOrMaskOrKey = null;
                    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                        if (token == XContentParser.Token.FIELD_NAME) {
                            toOrFromOrMaskOrKey = parser.currentName();
                        } else if (token == XContentParser.Token.VALUE_NUMBER) {
                            if ("from".equals(toOrFromOrMaskOrKey)) {
                                from = parser.doubleValue();
                            } else if ("to".equals(toOrFromOrMaskOrKey)) {
                                to = parser.doubleValue();
                            }
                        } else if (token == XContentParser.Token.VALUE_STRING) {
                            if ("from".equals(toOrFromOrMaskOrKey)) {
                                fromAsStr = parser.text();
                            } else if ("to".equals(toOrFromOrMaskOrKey)) {
                                toAsStr = parser.text();
                            } else if ("key".equals(toOrFromOrMaskOrKey)) {
                                key = parser.text();
                            } else if ("mask".equals(toOrFromOrMaskOrKey)) {
                                mask = parser.text();
                            }
                        }
                    }
                    RangeAggregator.Range range = new RangeAggregator.Range(key, from, fromAsStr, to, toAsStr);
                    if (mask != null) {
                        parseMaskRange(mask, range, aggregationName, context);
                    }
                    ranges.add(range);
                }
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("keyed".equals(currentFieldName)) {
                keyed = parser.booleanValue();
            } 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 (ranges == null) {
        throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalIPv4Range.FACTORY, ranges, keyed);
}
 
示例7
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser<ValuesSource.Numeric> vsParser = ValuesSourceParser.numeric(aggregationName, InternalDateRange.TYPE, context)
            .targetValueType(ValueType.DATE)
            .formattable(true)
            .build();

    List<RangeAggregator.Range> ranges = null;
    boolean keyed = false;

    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 (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else if (token == XContentParser.Token.START_ARRAY) {
            if ("ranges".equals(currentFieldName)) {
                ranges = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    double from = Double.NEGATIVE_INFINITY;
                    String fromAsStr = null;
                    double to = Double.POSITIVE_INFINITY;
                    String toAsStr = null;
                    String key = null;
                    String toOrFromOrKey = null;
                    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                        if (token == XContentParser.Token.FIELD_NAME) {
                            toOrFromOrKey = parser.currentName();
                        } else if (token == XContentParser.Token.VALUE_NUMBER) {
                            if ("from".equals(toOrFromOrKey)) {
                                from = parser.doubleValue();
                            } else if ("to".equals(toOrFromOrKey)) {
                                to = parser.doubleValue();
                            } else {
                                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName
                                        + "]: [" + currentFieldName + "].", parser.getTokenLocation());
                            }
                        } else if (token == XContentParser.Token.VALUE_STRING) {
                            if ("from".equals(toOrFromOrKey)) {
                                fromAsStr = parser.text();
                            } else if ("to".equals(toOrFromOrKey)) {
                                toAsStr = parser.text();
                            } else if ("key".equals(toOrFromOrKey)) {
                                key = parser.text();
                            } else {
                                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].", parser.getTokenLocation());
                            }
                        }
                    }
                    ranges.add(new RangeAggregator.Range(key, from, fromAsStr, to, toAsStr));
                }
            }
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("keyed".equals(currentFieldName)) {
                keyed = parser.booleanValue();
            } 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 (ranges == null) {
        throw new SearchParseException(context, "Missing [ranges] in ranges aggregator [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    return new RangeAggregator.Factory(aggregationName, vsParser.config(), InternalDateRange.FACTORY, ranges, keyed);
}
 
示例8
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser vsParser = ValuesSourceParser.numeric(aggregationName, InternalHistogram.TYPE, context)
            .targetValueType(ValueType.NUMERIC)
            .formattable(true)
            .build();

    boolean keyed = false;
    long minDocCount = 0;
    InternalOrder order = (InternalOrder) InternalOrder.KEY_ASC;
    long interval = -1;
    ExtendedBounds extendedBounds = null;
    long offset = 0;

    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 (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else if (token.isValue()) {
            if ("interval".equals(currentFieldName)) {
                interval = parser.longValue();
            } else if ("min_doc_count".equals(currentFieldName) || "minDocCount".equals(currentFieldName)) {
                minDocCount = parser.longValue();
            } else if ("keyed".equals(currentFieldName)) {
                keyed = parser.booleanValue();
            } else if ("offset".equals(currentFieldName)) {
                offset = parser.longValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            if ("order".equals(currentFieldName)) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                    if (token == XContentParser.Token.FIELD_NAME) {
                        currentFieldName = parser.currentName();
                    } else if (token == XContentParser.Token.VALUE_STRING) {
                        String dir = parser.text();
                        boolean asc = "asc".equals(dir);
                        if (!asc && !"desc".equals(dir)) {
                            throw new SearchParseException(context, "Unknown order direction [" + dir + "] in aggregation ["
                                    + aggregationName + "]. Should be either [asc] or [desc]", parser.getTokenLocation());
                        }
                        order = resolveOrder(currentFieldName, asc);
                    }
                }
            } else if (context.parseFieldMatcher().match(currentFieldName, EXTENDED_BOUNDS)) {
                extendedBounds = new ExtendedBounds();
                while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                    if (token == XContentParser.Token.FIELD_NAME) {
                        currentFieldName = parser.currentName();
                    } else if (token.isValue()) {
                        if ("min".equals(currentFieldName)) {
                            extendedBounds.min = parser.longValue(true);
                        } else if ("max".equals(currentFieldName)) {
                            extendedBounds.max = parser.longValue(true);
                        } else {
                            throw new SearchParseException(context, "Unknown extended_bounds key for a " + token + " in aggregation ["
                                    + aggregationName + "]: [" + currentFieldName + "].", parser.getTokenLocation());
                        }
                    }
                }

            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in aggregation [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    if (interval < 1) {
        throw new SearchParseException(context,
                "Missing required field [interval] for histogram aggregation [" + aggregationName + "]", parser.getTokenLocation());
    }

    Rounding rounding = new Rounding.Interval(interval);
    if (offset != 0) {
        rounding = new Rounding.OffsetRounding((Rounding.Interval) rounding, offset);
    }

    if (extendedBounds != null) {
        // with numeric histogram, we can process here and fail fast if the bounds are invalid
        extendedBounds.processAndValidate(aggregationName, context, ValueParser.RAW);
    }

    return new HistogramAggregator.Factory(aggregationName, vsParser.config(), rounding, order, keyed, minDocCount, extendedBounds,
            new InternalHistogram.Factory());

}
 
示例9
public BaseAggregationBuilder(final String name) {
  super(name, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
}
 
示例10
/**
 * Read from a stream.
 */
public BaseAggregationBuilder(final StreamInput in) throws IOException {
  super(in, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
}
 
示例11
private PathHierarchyAggregationBuilder(String name, ValueType valueType) {
    super(name, CoreValuesSourceType.ANY, valueType);
}
 
示例12
private DateHierarchyAggregationBuilder(String name, ValueType valueType) {
    super(name, CoreValuesSourceType.ANY, valueType);
}
 
示例13
private GeoShapeBuilder(String name, ValueType valueType) {
    super(name, CoreValuesSourceType.ANY, valueType);
}
 
示例14
public GeoPointClusteringAggregationBuilder(String name) {
    super(name, CoreValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
}