0

I have get the aggregation from reactive elastic search client, but I don't know how to parse it to transfer it into my domain object. Any suggestion is welcome.

YearMonth yearMonth = YearMonth.of(year, month);
LocalDate firstOfMonth = yearMonth.atDay(1);
LocalDate lastOfMonth = yearMonth.atEndOfMonth();
final String yearMonthString = yearMonth.toString().replace("-", "");

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
        .filter(QueryBuilders.rangeQuery("trade date")
                .gte( firstOfMonth.atStartOfDay(ZoneId.of(EST)).withZoneSameInstant(ZoneOffset.UTC))
                .lte(lastOfMonth
                        .atTime(23, 59, 59)
                        .atZone(ZoneId.of(EST))
                        .withZoneSameInstant(ZoneOffset.UTC)));

List<CompositeValuesSourceBuilder<?>> sources = new ArrayList<>();
sources.add(new TermsValuesSourceBuilder("client").field("client.keyword"));
sources.add(new TermsValuesSourceBuilder("region").field("region.keyword"));


CompositeAggregationBuilder compositeAgg =
        new CompositeAggregationBuilder("my_group", sources)
                .subAggregation(AggregationBuilders.sum("lot_sum").field("lots"))
                .subAggregation(AggregationBuilders.sum("count_sum").field("trade_count"))
                .size(65536);

SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(boolQueryBuilder);
sourceBuilder.aggregation(compositeAgg);

SearchRequest searchRequest = new SearchRequest("very_good_index_name"+ dateSuffix()).source(sourceBuilder);

return reactiveElasticsearchClient.aggregate(searchRequest).map(aggregation -> {
  //How to get bucket and key which like in unreactive API?

    return aggregation;
});

In debug mode, I could see it have bucket which contains the value I need, like key and aggregation value, but somehow I can't access that enter image description here

1
  • No one use spring data to query aggregation in ES with reactive?
    – Jason
    Commented Jun 13 at 2:26

0