Aggregation for count values on boolean


I have 100 documents with an boolean field, 80 docs are true, 20 are false.

How can I return only the "true" ones in an aggregation?

I'm looking for an aggregation similar to this sql:

SELECT count(*) FROM docs WHERE field = 'true';

I've tried an Term-Aggregation, but that returns also the false-values:

"myField": {

    "doc_count_error_upper_bound": 0,
    "sum_other_doc_count": 0,
    "buckets": [
            "key": 0,
            "key_as_string": "false",
            "doc_count": 20
            "key": 1,
            "key_as_string": "true",
            "doc_count": 80

Is there a shorter aggregation, which count's only me "true"-fields?

Best regards,

Why doing an aggregation for that?

You can just run a normal query which filters on that field with size=0. And just get the total hits.

If you really want an aggregation, use the filter agg.

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