How to aggregate boolean values in elastic search? How to aggregate boolean values in elastic search? elasticsearch elasticsearch

How to aggregate boolean values in elastic search?


First 0/1 representation is not exactly ES Boolean representation. There is a Boolean type for as true/false.Second stats aggregation can be only done on numeric field and not on string field. That is why it worked for 0/1 representation.

You can transform this value using scripts in extended stats

{    "aggs" : {        ...        "aggs" : {            "grades_stats" : {                "extended_stats" : {                    "field" : "grade",                    "script" : "_value == 'T' ? 1 : 0",                }            }        }    }}

To see some example usage of scripting in aggregation , you can look here.