Home > Back-end >  Empty Elasticsearch aggregations being returned in the response
Empty Elasticsearch aggregations being returned in the response

Time:10-02

I am using aggregations on Elasticsearch through Java API. I can see up until the response object is returned, that aggregations are there within the responseenter image description here

But Postman returns this:

enter image description here

Any idea why or how to debug this even further? Is spring-data-elasticsearch doing something which I don't understand here?

Update: I have a hunch it has to do with jackson mapping somehow? Getting this as one of the bucket results: enter image description here

I should be expecting something like this:

enter image description here

CodePudding user response:

Try to remove the numberOfHits there is a limit size for aggregation

https://discuss.elastic.co/t/maximum-aggregation-response-limit/103779

CodePudding user response:

It started working after I commented out this line:

  mvc:
    converters:
      preferred-json-mapper: gson

in my application.yml. So now its using the jackson mapper. Also added this:

public class JacksonConfig   {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer changeKeyAsNumber() {
        return new Jackson2ObjectMapperBuilderCustomizer() {

            @Override
            public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
                jacksonObjectMapperBuilder.mixIn(ParsedStringTerms.ParsedBucket.class, MixIn.class);
            }
        };
    }

}

abstract class MixIn {
    @JsonIgnore
    abstract public Number getKeyAsNumber();
}

according to: Getting jackson parsing error while serializing AggregatedPage in spring data elasticsearch

  • Related