Trigger an alert when the count after an aggregation is greater than


I am new using Opnedistro and I would like to create a monitoring script to be alerted when the count after an aggrregation is greater than 8 for example :

    "size": 0,
    "aggs": {
        "number_of_esa_rules_up": {
            "terms": {
                "field": "metrics.rsa.correlation.metrics.rule-metrics.value.ruleName.keyword",
                "size": 100

Could you please tell me how can I count the result of this search query and then make a condition to trigger an alert if it’s exceed a value ?

Best regards