# Unable to set trackTotalHits to true in Java RestHighLevelClient

**URL:** <https://discuss.elastic.co/t/unable-to-set-tracktotalhits-to-true-in-java-resthighlevelclient/309284>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [July 11, 2022, 2:49am UTC](https://discuss.elastic.co/t/unable-to-set-tracktotalhits-to-true-in-java-resthighlevelclient/309284 "2022-07-11T02:49:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shashi-bhushan](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@shashi-bhushan](https://discuss.elastic.co/u/shashi-bhushan)\
**Post date:** [July 11, 2022, 2:49am UTC](https://discuss.elastic.co/t/unable-to-set-tracktotalhits-to-true-in-java-resthighlevelclient/309284/1 "2022-07-11T02:49:51Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/1/01cb33686f7a42b20718d10300034c3e5cbbc753.png)

v6.7.0

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/3/f3e8916745c032d869e01d2487bc592c5fb73146.png)

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

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [July 11, 2022, 1:25pm UTC](https://discuss.elastic.co/t/unable-to-set-tracktotalhits-to-true-in-java-resthighlevelclient/309284/2 "2022-07-11T13:25:45Z")

</div>

Hi @shashi-bhushan  
You can set here:

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

```

You can read in [git](https://github.com/elastic/elasticsearch/issues/33028) the reasons for this change from version 6.x to 7.x and also in this answer on [stackoverflow](https://stackoverflow.com/a/66450951/18778181).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 8, 2022, 1:26pm UTC](https://discuss.elastic.co/t/unable-to-set-tracktotalhits-to-true-in-java-resthighlevelclient/309284/3 "2022-08-08T13:26:05Z")

</div>

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