Unable to set trackTotalHits to true in Java RestHighLevelClient

Hi,

I'm unable to make use of track_total_hits flag when using Java RestHighLevelClient. I was checking Elastic code a bit and it looks like the RequestConverters#addSearchRequestParams method is adding only certain params from SearchRequest object. I confirmed this is indeed the case with ES v7.13.0 and v6.7.0 (calling RequestConverters.search(r, "_search") via debugger)

v7.13.0

v6.7.0

The call to RequestConverters.search(searchRequest, "_search").getParameters(); shows track_total_hits isn't part of parameters, even though trackTotalHits is true/intValue.

Please confirm if this could be a bug or there's some other way to setTrackTotalHits when using RestHighLevelClient. Thanks

Hi @shashi-bhushan
You can set here:

    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.trackTotalHitsUpTo(10);

You can read in git the reasons for this change from version 6.x to 7.x and also in this answer on stackoverflow.

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