Reading comment data with Elasticsearch aggregation

Once comments are added, they must be visible when the user opens the blog. This scenario is straightforward. Since comments are nested objects of a blog, when we read a blog with the following API, all its comments are also available as part of the blog object:

 Optional<Blog> blogObj = blogRepository.findById(blogId);    if(blogObj.isPresent()) {      return blogObj.get();    }else {      return null;    }

The findById method is provided out of the box by a default repository implementation, available during runtime. We pass blogId, and it will fetch all details of the blog along with comments (as nested objects).

The second scenario for reading comment is the admin user opens the manage-comment page, where ...

Get Spring 5.0 Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.