AggregationsContainer after Updating from Elastic 7 to 8 (+Spring 3, JDK 17)

124 views Asked by At

Hello dear community,

I have upgraded Spring Boot to 3.1.5 and JDK to 17 and my ElasticSearch from 7.x to 8.x, now I have the problem that I can't find a solution how to refactor aggregations, which still had a .get(String x) method in version 4.0.0.RELEASE, so that they work in my currently used version of spring-data-elasticsearch. As I am still relatively new to the world of ElasticSearch, I also wanted to ask whether the dependencies used are compatible with ES8? As far as I understand it, the rest high level client is no longer used in the ES8 version and the java client is used instead. Is that correct? I would be very happy about some help! :)

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
  <version>3.1.1</version> <!--Last version is 3.2.0-->
</dependency>
<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-elasticsearch</artifactId>
  <version>4.3.6</version> <!--Last version is 5.2.0-->
</dependency>
<dependency>
  <groupId>co.elastic.clients</groupId>
  <artifactId>elasticsearch-java</artifactId>
  <version>8.11.1</version> <!--Is last version-->
</dependency>

public static Set<Integer> getAggregations(SearchHits<ElasticSearchArticleDto> search, String aggregation)
  {
    Set<Integer> result = new LinkedHashSet<>();
    if (search.getAggregations() != null && (search.getAggregations()).**get**(aggregation) != null)
    {
      ((ParsedLongTerms) (search.getAggregations()).**get**(aggregation)).getBuckets()
        .forEach(bucket -> result.add(bucket.getKeyAsNumber().intValue()));
    }
    return result;
}

Spring Boot 3.1.5, Java 17, ES8 Upgrade

1

There are 1 answers

0
P.J.Meisch On

I doubt that this version mix will work

  • Spring Boot 3.1 uses Spring Data Elasticsearch 5.1 and Elasticsearch 8.7, Spring 6
  • Spring Data Elasticsearch 4.3 is built with Spring 5.3 and Elasticsearch 7.15

As for the returned aggregations from Spring Data Elasticsearch 5 on, you will have to check the classes that are returned from the Elasticsearch libraries, Spring Data Elasticsearch doen't use it's own classes there.