# prepareCount API deprecated from 2.1. The alternate not working

**URL:** <https://discuss.elastic.co/t/preparecount-api-deprecated-from-2-1-the-alternate-not-working/39058>\
**Category:** Elasticsearch\
**Created:** [January 13, 2016, 5:42am UTC](https://discuss.elastic.co/t/preparecount-api-deprecated-from-2-1-the-alternate-not-working/39058 "2016-01-13T05:42:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trupti\_mali](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@trupti\_mali](https://discuss.elastic.co/u/trupti_mali)\
**Post date:** [January 13, 2016, 5:42am UTC](https://discuss.elastic.co/t/preparecount-api-deprecated-from-2-1-the-alternate-not-working/39058/1 "2016-01-13T05:42:36Z")

</div>

Hi,  
PrepareCount API has been deprecated from 2.1 . I was trying the alternate way of using prepareSearch with setSize as zero. But that didnt seem to work. It basically returned me no values at all.

SearchRequestBuilder srBuilder = client.prepareSearch();  
srBuilder.setTypes(AUDIT\_TYPE);  
srBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH);  
srBuilder.setFetchSource(true);  
srBuilder.setSize(0);  
srBuilder.setQuery(queryBuilder); ///added a termQuery

Am I doing anything wrong here?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 13, 2016, 6:32am UTC](https://discuss.elastic.co/t/preparecount-api-deprecated-from-2-1-the-alternate-not-working/39058/2 "2016-01-13T06:32:17Z")

</div>

What do you mean by "no value"?

How does the response object look like?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [January 13, 2016, 3:54pm UTC](https://discuss.elastic.co/t/preparecount-api-deprecated-from-2-1-the-alternate-not-working/39058/3 "2016-01-13T15:54:30Z")

</div>

do you do srBuilder.get() somewhere to actually send the request and get back the response? This type of request provides no results but the total hits will contain the number of matching documents.

---

<div class="post-metadata">

**Author:** ![trupti\_mali](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@trupti\_mali](https://discuss.elastic.co/u/trupti_mali)\
**Post date:** [January 14, 2016, 9:38am UTC](https://discuss.elastic.co/t/preparecount-api-deprecated-from-2-1-the-alternate-not-working/39058/4 "2016-01-14T09:38:22Z")

</div>

> [@trupti\_mali](#):
>
> srBuilder.setTypes(AUDIT\_TYPE); srBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH); srBuilder.setFetchSource(true); srBuilder.setSize(0); srBuilder.setQuery(queryBuilder);

Ah Right !! I think you were right - I was looking into the array returned and not at total hits variable

Thanks Luca

---

<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:** [July 5, 2017, 11:24pm UTC](https://discuss.elastic.co/t/preparecount-api-deprecated-from-2-1-the-alternate-not-working/39058/5 "2017-07-05T23:24:37Z")

</div>


