The new version of es "_count" doesn't support post_filter


(Yanyumiao) #1

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?


(David Pilato) #2

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


(Yanyumiao) #4

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


(David Pilato) #5

Please format your code using </> icon as explained in this guide. 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: https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-count.html

What has been removed is search_type=count: 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.


(Yanyumiao) #6

I have a dsl like this:

{
    "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+)


(David Pilato) #7

But you can run this right?

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:

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.


(Yanyumiao) #8

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.


(David Pilato) #9

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?


(Yanyumiao) #10

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


(David Pilato) #11

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.


(system) closed #12

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