@Override
    public CheckResult runCheck() {
        try {
            final String filter = buildQueryFilter(stream.getId(), query);
            // TODO we don't support cardinality yet
            final FieldStatsResult fieldStatsResult = searches.fieldStats(field, "*", filter,
                RelativeRange.create(time * 60), false, true, false);

            if (fieldStatsResult.count() == 0) {
                LOG.debug("Alert check <{}> did not match any messages. Returning not triggered.", type);
                return new NegativeCheckResult();
            }

            final double result;
            switch (type) {
                case MEAN:
                    result = fieldStatsResult.mean();
                    break;
                case MIN:
                    result = fieldStatsResult.min();
                    break;
                case MAX:
                    result = fieldStatsResult.max();
                    break;
                case SUM:
                    result = fieldStatsResult.sum();
                    break;
                case STDDEV:
                    result = fieldStatsResult.stdDeviation();
                    break;
                default:
                    LOG.error("No such field value check type: [{}]. Returning not triggered.", type);
                    return new NegativeCheckResult();
            }

            LOG.debug("Alert check <{}> result: [{}]", id, result);

            if (Double.isInfinite(result)) {
                // This happens when there are no ES results/docs.
                LOG.debug("Infinite value. Returning not triggered.");
                return new NegativeCheckResult();
            }

            final boolean triggered;
            switch (thresholdType) {
                case HIGHER:
                    triggered = result > threshold.doubleValue();
                    break;
                case LOWER:
                    triggered = result < threshold.doubleValue();
                    break;
                default:
                    triggered = false;
            }

            if (triggered) {
                final String resultDescription = "Field " + field + " had a " + type + " of "
                    + decimalFormat.format(result) + " in the last " + time + " minutes with trigger condition "
                    + thresholdType + " than " + decimalFormat.format(threshold) + ". "
                    + "(Current grace time: " + grace + " minutes)";

                final List<MessageSummary> summaries;
                if (getBacklog() > 0) {
                    final List<ResultMessage> searchResult = fieldStatsResult.searchHits();
                    summaries = Lists.newArrayListWithCapacity(searchResult.size());
                    for (ResultMessage resultMessage : searchResult) {
                        final Message msg = resultMessage.getMessage();
                        summaries.add(new MessageSummary(resultMessage.getIndex(), msg));
                    }
                } else {
                    summaries = Collections.emptyList();
                }

                return new CheckResult(true, this, resultDescription, Tools.nowUTC(), summaries);
            } else {
                return new NegativeCheckResult();
            }
        } catch (InvalidRangeParametersException e) {
            // cannot happen lol
            LOG.error("Invalid timerange.", e);
            return null;
        } catch (FieldTypeException e) {
            LOG.debug("Field [{}] seems not to have a numerical type or doesn't even exist at all. Returning not triggered.", field, e);
            return new NegativeCheckResult();
        }
    }
@Test
    public void testRunCheckLowerNegative() throws Exception {
        for (FieldValueAlertCondition.CheckType checkType : FieldValueAlertCondition.CheckType.values()) {
            final double threshold = 50.0;
            final double higherThanThreshold = threshold + 10;
            FieldValueAlertCondition fieldValueAlertCondition = getFieldValueAlertCondition(getParametersMap(0, 0,
                FieldValueAlertCondition.ThresholdType.LOWER,
                checkType, threshold, "response_time"),
                alertConditionTitle);

            fieldStatsShouldReturn(getFieldStatsResult(checkType, higherThanThreshold));

            AlertCondition.CheckResult result = fieldValueAlertCondition.runCheck();

            assertNotTriggered(result);
        }
    }