Using ES query in Spring Boot

  1. We have to translate this complex and big query to JavaAPI. Which is the best way to accomplish this?
  • Start with the first filter and then add aggregations and subaggregations to it?
  • Start with the deepest subaggregation and then wrapp it in the upper level?

The former. Note that if you use the High Level Rest Client, it exposes lot of helpers to build that from Java.

I have a project example here:

You can read more about this example here: https://david.pilato.fr/blog/2015-05-09-advanced-search-for-your-legacy-application/

  1. As you can see, JSON response does not have anything to do with document saved. We have no idea how to return this data to Java.
  • Is it better to return plain JSON and work with it in Angular?

If you don't need to do special transformations with your data but just display the result on a page, indeed sending the JSON response as is back to the front end is the easiest way IMO.

  • Is it possible to create a complex POJO and marshall ES JSON to that POJO?

You can use Jackson for that.