Search in sources :

Example 6 with SimpleValue

use of org.elasticsearch.search.aggregations.pipeline.SimpleValue in project elasticsearch by elastic.

the class MovAvgIT method assertBucketContents.

private void assertBucketContents(Histogram.Bucket actual, Double expectedCount, Double expectedValue) {
    // This is a gap bucket
    SimpleValue countMovAvg = actual.getAggregations().get("movavg_counts");
    if (expectedCount == null) {
        assertThat("[_count] movavg is not null", countMovAvg, nullValue());
    } else if (Double.isNaN(expectedCount)) {
        assertThat("[_count] movavg should be NaN, but is [" + countMovAvg.value() + "] instead", countMovAvg.value(), equalTo(Double.NaN));
    } else {
        assertThat("[_count] movavg is null", countMovAvg, notNullValue());
        assertTrue("[_count] movavg does not match expected [" + countMovAvg.value() + " vs " + expectedCount + "]", nearlyEqual(countMovAvg.value(), expectedCount, 0.1));
    }
    // This is a gap bucket
    SimpleValue valuesMovAvg = actual.getAggregations().get("movavg_values");
    if (expectedValue == null) {
        assertThat("[value] movavg is not null", valuesMovAvg, Matchers.nullValue());
    } else if (Double.isNaN(expectedValue)) {
        assertThat("[value] movavg should be NaN, but is [" + valuesMovAvg.value() + "] instead", valuesMovAvg.value(), equalTo(Double.NaN));
    } else {
        assertThat("[value] movavg is null", valuesMovAvg, notNullValue());
        assertTrue("[value] movavg does not match expected [" + valuesMovAvg.value() + " vs " + expectedValue + "]", nearlyEqual(valuesMovAvg.value(), expectedValue, 0.1));
    }
}
Also used : SimpleValue(org.elasticsearch.search.aggregations.pipeline.SimpleValue)

Aggregations

SimpleValue (org.elasticsearch.search.aggregations.pipeline.SimpleValue)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)4 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)4 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)4 Bucket (org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket)3 Avg (org.elasticsearch.search.aggregations.metrics.avg.Avg)2 PipelineAggregatorBuilders.movingAvg (org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.movingAvg)2 SimpleModel (org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel)2 CompiledScript (org.elasticsearch.script.CompiledScript)1 Script (org.elasticsearch.script.Script)1 PipelineAggregationHelperTests (org.elasticsearch.search.aggregations.pipeline.PipelineAggregationHelperTests)1 PipelineAggregatorBuilders.bucketScript (org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.bucketScript)1 Derivative (org.elasticsearch.search.aggregations.pipeline.derivative.Derivative)1 HoltWintersModel (org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltWintersModel)1