Move from High Level REST client to Java API Client

I have to move from High Level REST client to Java API Client
I would like to show one method I have to replace and learn from that . This is old method:

public List<Map<String, Object>> getPublicFilters() {

		SearchRequest searchRequest = new SearchRequest("filter-template");

		searchRequest.source(new SearchSourceBuilder().query(QueryBuilders.matchQuery("private", false)));

		return, RequestOptions.DEFAULT).getHits().getHits())

I understand it have to be replaced to something like this: -> searchRequest
   .query(queryBuilder ->

indexName is probably "filter-template"
and I assume "route" have to be replaced with "private"
but what about searchText ?
And Flight.class - is it Object in ma case ?


indexName is probably "filter-template"


and I assume "route" have to be replaced with "private"


but what about searchText ?

I believe it should be false. But I'd use a term query instead of a match query as I guess your field is mapped as a boolean...

And Flight.class - is it Object in ma case ?

I'd recommend it to be your Java Bean (the business object). That's one of the cool additions of this Java client. You can directly index your java beans and get back your java beans at search time...

You should not start a new project with that one for sure.
If you are planning to use 8.x, switch to it. I don't think the HLClient will be able to support it and actually a lot of new APIs are not available in the HLClient.

In general, I'd recommend:

  • Upgrade your 7.x or below cluster to 7.17.x
  • Switch to the new Java API Client with the 7.17.x version
  • Then, when possible, upgrade your client and cluster to 8.x (the latest version)
1 Like

But is seems there will be no problem to use HLClient with 8.x , no ?

I said that you should not. Not that you can't... I'd really avoid it if possible.
This setting has been made for existing code when people want to upgrade the cluster to 8.x but don't have time to rewrite the code using the new Java API Client.

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