Search code examples
javaspring-bootelasticsearchspring-data-elasticsearchspring-boot-3

How to implement CompositeAggregationSource with springboot 3.2.10 and elasticsearch 8.12.1


We have implemented below code using springboot 3.1.0 and elastic search 8.10.4

CompositeAggregationSource compositeAggregationSource = CompositeAggregationSource
                .of(ca -> ca.terms(TermsAggregation.of(t -> t.field(Constants.name))));

Now we have upgraded springboot to 3.2.10 and elasticsearch to 8.12.1 And ca.terms() method from above code is not supported in these version, how to implement above method with these upgraded version.


Solution

  • I think you are mistaken, because in the library co.elastic.clients:elasticsearch-java the CompositeAggregationSource.of() method should receive an argument of type Function<CompositeAggregationSource.Builder, ObjectBuilder<CompositeAggregationSource>> both in version 8.10.4 and version 8.12.1. So it makes sense for you to replace TermsAggregation.of() in your code with CompositeTermsAggregation.of()

    CompositeAggregationSource compositeAggregationSource = CompositeAggregationSource
    .of(ca -> ca.terms(CompositeTermsAggregation.of(t -> t.field(Constants.name))));