# Using SearchType "count" alternatives

**URL:** <https://discuss.elastic.co/t/using-searchtype-count-alternatives/263530>\
**Category:** Elasticsearch\
**Created:** [February 7, 2021, 9:55pm UTC](https://discuss.elastic.co/t/using-searchtype-count-alternatives/263530 "2021-02-07T21:55:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nara1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nara1](https://discuss.elastic.co/u/nara1)\
**Post date:** [February 7, 2021, 9:55pm UTC](https://discuss.elastic.co/t/using-searchtype-count-alternatives/263530/1 "2021-02-07T21:55:07Z")

</div>

I have a use case where I need to use the "size" parameter in my query. I have seen the recommendation to perform two queries-- one to retrieve the count, and a second query using that count as the "size" parameter, to ensure I'm getting all my results without having to set "size" to MAX\_INTEGER.

I am using JestClient to execute my query-- when I try the following search, I get the error below:

```auto
        final Search countSearch = new Search.Builder(searchSourceBuilder.toString())
                .setSearchType(SearchType.COUNT)
                .build();

```

```auto
"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"No search type for [count]"

```

Online I am seeing that the count search type is deprecated, and that we should use "size = 0" for this purpose. However using "size = 0" just returns 0 results for me.

Using Scroll doesn't work for my use case, because on the client side these data are going to be downloaded into a csv file, not displayed in a UI.

What are my options for this? Thanks!

---

<div class="post-metadata">

**Author:** ![nara1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@nara1](https://discuss.elastic.co/u/nara1)\
**Post date:** [February 8, 2021, 4:28pm UTC](https://discuss.elastic.co/t/using-searchtype-count-alternatives/263530/2 "2021-02-08T16:28:54Z")

</div>

Any advice on this one? Thanks!

---

<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:** [March 8, 2021, 4:29pm UTC](https://discuss.elastic.co/t/using-searchtype-count-alternatives/263530/3 "2021-03-08T16:29:14Z")

</div>

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