# The new version of es "\_count" doesn't support post\_filter

**URL:** <https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825>\
**Category:** Elasticsearch\
**Created:** [July 5, 2017, 3:05am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825 "2017-07-05T03:05:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yanyumiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanyumiao/32/19773_2.png) [@yanyumiao](https://discuss.elastic.co/u/yanyumiao)\
**Post date:** [July 5, 2017, 3:05am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/1 "2017-07-05T03:05:13Z")

</div>

hi:

I found that es v2.3.3 [\_count] and [\_search] both support [post\_filter]  
but es v5.0.2 [\_count] does not support [post\_filter].  
I also found es v5.4.2 has the same problem.

Is that a BUG?

---

<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:** [July 5, 2017, 4:13am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/2 "2017-07-05T04:13:39Z")

</div>

\_count has been removed in 5.0. Search for breaking changes in the guide.

---

<div class="post-metadata">

**Author:** ![yanyumiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanyumiao/32/19773_2.png) [@yanyumiao](https://discuss.elastic.co/u/yanyumiao)\
**Post date:** [July 5, 2017, 8:27am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/4 "2017-07-05T08:27:40Z")

</div>

wow, I doesn't found some other way to replace "[\_count] with [post\_filter]" in new es.  
I think the "[\_count] with [post\_filter]" is useful, and I suggest es can give this fature

look at this:  
/\_count -d '{"query":{...}, "post\_filter":{"range":{...}}}'  
I just want the count, But now, I have to use \_search to get the count.

thank you for answer

---

<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:** [July 5, 2017, 9:02am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/5 "2017-07-05T09:02:50Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

> I just want the count, But now, I have to use \_search to get the count.

Hmm. Sounds like I was wrong. `_count` API still exists: [Count API | Elasticsearch Reference [5.4] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-count.html)

What has been removed is `search_type=count`: [Search and Query DSL changes | Elasticsearch Reference [5.4] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/breaking_50_search_changes.html#_literal_search_type_count_literal_removed)

I think it's perfectly to call `_search` with `size: 0`. It will behave like a count actually.

---

<div class="post-metadata">

**Author:** ![yanyumiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanyumiao/32/19773_2.png) [@yanyumiao](https://discuss.elastic.co/u/yanyumiao)\
**Post date:** [July 5, 2017, 9:13am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/6 "2017-07-05T09:13:17Z")

</div>

I have a dsl like this:

```auto
{
    "query":{
        "query_string":{
            "query":"request_uri:"/*.html""
        }
    },
    "post_filter":{
        "range":{
            "@timestamp_date":{
                "gte":"2017-07-05 09:07:00",
                "lt":"2017-07-05 09:08:00",
                "format":"yyyy-MM-dd HH:mm:ss"
            }
        }
    }
}

```

when es v2.3.3, you can use this on [\_count] and [\_search]  
but you can not use this on [\_count] when es v5.0.2 and es v5.4.2 (maybe all es v5.0+)

---

<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:** [July 5, 2017, 9:32am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/7 "2017-07-05T09:32:11Z")

</div>

But you can run this right?

```auto
GET _search 
{
    "size": 0,
    "query":{
        "query_string":{
            "query":"request_uri:"/*.html""
        }
    },
    "post_filter":{
        "range":{
            "@timestamp_date":{
                "gte":"2017-07-05 09:07:00",
                "lt":"2017-07-05 09:08:00",
                "format":"yyyy-MM-dd HH:mm:ss"
            }
        }
    }
}

```

I opened actually:

> <https://github.com/elastic/elasticsearch/issues/25548>

Because I believe we should not support 2 APIs to do the same thing with one of the APIs which does not support everything that the other one supports.

---

<div class="post-metadata">

**Author:** ![yanyumiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanyumiao/32/19773_2.png) [@yanyumiao](https://discuss.elastic.co/u/yanyumiao)\
**Post date:** [July 5, 2017, 12:43pm UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/8 "2017-07-05T12:43:03Z")

</div>

Thank you very much for your answer.  
Yes, I can run it by set "size to 0".  
I have an env like that : I should get the count first, and then I set this count to size for search api.

---

<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:** [July 5, 2017, 1:12pm UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/9 "2017-07-05T13:12:53Z")

</div>

> I have an env like that : I should get the count first, and then I set this count to size for search api.

That sounds a bad idea to me.  
To you mean that you want to display on a single page 1000000 documents if you have 1m matching docs?

---

<div class="post-metadata">

**Author:** ![yanyumiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanyumiao/32/19773_2.png) [@yanyumiao](https://discuss.elastic.co/u/yanyumiao)\
**Post date:** [July 6, 2017, 2:30am UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/10 "2017-07-06T02:30:44Z")

</div>

I search about 15k doc every min. but not for display, for calculate.

---

<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:** [July 6, 2017, 4:36pm UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/11 "2017-07-06T16:36:34Z")

</div>

Why counting then? If the page size is 15000, set it to 15000. You need to change some index settings though to allow more than 10000. Or use scroll API.

---

<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 3, 2017, 4:36pm UTC](https://discuss.elastic.co/t/the-new-version-of-es--count-doesnt-support-post-filter/91825/12 "2017-08-03T16:36:38Z")

</div>

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