0

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

Ahmed
  • 121
  • 6
  • 18

2 Answers2

0

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

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

Noa
  • 315
  • 1
  • 7
  • 31
  • im confused as to why my response object has all the data but it just isn't being returned in the http response i guess. And I believe it doesn't have to do with numberOfHits, tried aggregating via another service and that one returned data – Ahmed Oct 01 '21 at 20:47
  • are you deserialize it to a specific type when you reservice the response? Also, I would like you to check the response message when it reaches your java-client – Noa Oct 01 '21 at 20:50
  • so that line highlighted in the first pic is the last point of execution of the code and after that the response is returned to the client. The return type of the method is the object type of the highlighted response. Can you clarify what you mean by check the response message when it reaches your java client? – Ahmed Oct 01 '21 at 20:57
  • that is your problem the object type is not highlighted as the image shows it is aggregation type. for test purpose just return it as a string and you will see your aggregation object – Noa Oct 01 '21 at 21:00
  • the response returned is of type ESResponse and the aggregation field highlighted is the ES aggregation. So the ESResponse pojo has private Aggregations aggregations; – Ahmed Oct 01 '21 at 21:22
0

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

Ahmed
  • 121
  • 6
  • 18