I suppose you need to check for the existence of the buckets array, as it might be empty - this is just a guess however.
First, please always format your exceptions as well, makes it much more readbale.
Second, if you add min_doc_count: 10 to your aggregation, the bucket will only be returned if it contains more than ten documents. With this change in your query in place, you just need to check if the size of the buckets is greater than 0.
If it still does not work, please share the full output of the execute watch API.
Turns out the issue was naming.
You cannot use numbers to name the fields you're calling as it causes an error later on.
In my case: 4XXerror.
I renamed it to errors, and it works perfectly fine.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.