Java High Level REST Client: result casting


I'm looking into Java High Level REST Client API and as far as I can see, there is to convinent ways to retrieve search result entity

  • As json string: getSourceAsString()
  • As map: getSourceAsMap()

However in Jest there is a way to cast search results right away:
List<Article> articles = result.getSourceAsObjectList(Article.class);

Is this feature planned for implementation, or I just missed something?

you can also retrieve the source as bytes through the getSourceRef method. You are right though. Jest uses Gson to map json to user provided objects. The high-level REST client doesn't do that. We don't want to have extra dependencies at this point, rather reduce them instead.

Looking at the Jest code it should be easy to do this from your application:

String json = searchHit.getSourceAsString();
Article obj = gson.fromJson(json, Article.class);

We are not currently planning on adding this feature to the client. Do let us know if this is a blocker for you or whether it is a reasonable decision.


I would say it is pretty reasonable, and it's not a blocker for me. Thank you for the response.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.