Search in sources :

Example 1 with GeoDistanceBuilder

use of org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceBuilder in project xp by enonic.

the class GeoDistanceAggregationQueryBuilderFactory method create.

AggregationBuilder create(final GeoDistanceAggregationQuery query) {
    final String fieldName = fieldNameResolver.resolve(query.getFieldName(), IndexValueType.GEO_POINT);
    final GeoDistanceBuilder geoDistanceBuilder = new GeoDistanceBuilder(query.getName()).field(fieldName).lat(query.getOrigin().getLatitude()).lon(query.getOrigin().getLongitude());
    if (!isNullOrEmpty(query.getUnit())) {
        geoDistanceBuilder.unit(DistanceUnit.fromString(query.getUnit()));
    }
    for (final DistanceRange range : query.getRanges()) {
        final String key = range.getKey();
        if (range.getFrom() == null) {
            addUnboundedTo(geoDistanceBuilder, range, key);
        } else if (range.getTo() == null) {
            addUnboundedFrom(geoDistanceBuilder, range, key);
        } else {
            addBoundedToAndFrom(geoDistanceBuilder, range, key);
        }
    }
    return geoDistanceBuilder;
}
Also used : GeoDistanceBuilder(org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceBuilder) DistanceRange(com.enonic.xp.query.aggregation.DistanceRange)

Aggregations

DistanceRange (com.enonic.xp.query.aggregation.DistanceRange)1 GeoDistanceBuilder (org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceBuilder)1