Search in sources :

Example 6 with RangeAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder in project vertigo by KleeGroup.

the class ESSearchRequestBuilder method numberRangeFacetToAggregationBuilder.

private static AggregationBuilder numberRangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
    final RangeAggregationBuilder rangeBuilder = // 
    AggregationBuilders.range(facetDefinition.getName()).field(dtField.getName());
    for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
        final String filterValue = facetRange.getListFilter().getFilterValue();
        Assertion.checkState(filterValue.contains(dtField.getName()), "RangeFilter query ({1}) should use defined fieldName {0}", dtField.getName(), filterValue);
        final String[] parsedFilter = DtListPatternFilterUtil.parseFilter(filterValue, RANGE_PATTERN).get();
        final Optional<Double> minValue = convertToDouble(parsedFilter[3]);
        final Optional<Double> maxValue = convertToDouble(parsedFilter[4]);
        if (!minValue.isPresent()) {
            rangeBuilder.addUnboundedTo(filterValue, maxValue.get());
        } else if (!maxValue.isPresent()) {
            rangeBuilder.addUnboundedFrom(filterValue, minValue.get());
        } else {
            // always min include and max exclude in ElasticSearch
            rangeBuilder.addRange(filterValue, minValue.get(), maxValue.get());
        }
    }
    return rangeBuilder;
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder)

Aggregations

RangeAggregationBuilder (org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder)6 DateRangeAggregationBuilder (org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder)3 GeoGridAggregationBuilder (org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder)2 DateHistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)2 HistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder)2 ExtendedStatsAggregationBuilder (org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder)2 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)1 HashMap (java.util.HashMap)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)1 SearchPlugin (org.elasticsearch.plugins.SearchPlugin)1 AggregationSpec (org.elasticsearch.plugins.SearchPlugin.AggregationSpec)1 PipelineAggregationSpec (org.elasticsearch.plugins.SearchPlugin.PipelineAggregationSpec)1 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)1 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)1 AdjacencyMatrixAggregationBuilder (org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder)1 ChildrenAggregationBuilder (org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder)1 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)1