Searchhits Aggregationcontainer doesn't contain method anymore

24 views Asked by At

I currently have the problem of having updated from an older spring-data-elasticsearch version to version 4.4.18. Unfortunately, I am still new to elastic search and am now wondering how I can solve the following problem.

Now, the problem here, is all documentation I've gone through so far suggests me to implement searchHits.getAggregations().get("distinct_projects"), but that's not available in Spring Data Elasticsearch 4.4.18, which we're using. According to the documentation here,

The SearchHitsclass does not contain the org.elasticsearch.search.aggregations.Aggregations anymore. Instead it now contains an instance of the org.springframework.data.elasticsearch.core.AggregationsContainer class

I would be very happy for any kind of constructive feedback. :)

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;
  }
0

There are 0 answers