|
33 | 33 | import org.elasticsearch.search.aggregations.metrics.sum.Sum;
|
34 | 34 | import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
|
35 | 35 | import org.elasticsearch.search.aggregations.pipeline.derivative.Derivative;
|
| 36 | +import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel; |
36 | 37 | import org.elasticsearch.search.aggregations.support.AggregationPath;
|
37 | 38 | import org.elasticsearch.test.ESIntegTestCase;
|
38 | 39 | import org.hamcrest.Matchers;
|
|
43 | 44 |
|
44 | 45 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
45 | 46 | import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
46 |
| -import static org.elasticsearch.search.aggregations.AggregationBuilders.filters; |
47 |
| -import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram; |
48 |
| -import static org.elasticsearch.search.aggregations.AggregationBuilders.stats; |
49 |
| -import static org.elasticsearch.search.aggregations.AggregationBuilders.sum; |
| 47 | +import static org.elasticsearch.search.aggregations.AggregationBuilders.*; |
50 | 48 | import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.derivative;
|
| 49 | +import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.movingAvg; |
51 | 50 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
52 | 51 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
|
53 | 52 | import static org.hamcrest.Matchers.closeTo;
|
@@ -614,6 +613,37 @@ public void testSingleValueAggDerivative_invalidPath() throws Exception {
|
614 | 613 | }
|
615 | 614 | }
|
616 | 615 |
|
| 616 | + public void testAvgMovavgDerivNPE() throws Exception { |
| 617 | + createIndex("movavg_npe"); |
| 618 | + ensureYellow("movavg_npe"); |
| 619 | + |
| 620 | + for (int i = 0; i < 10; i++) { |
| 621 | + Integer value = i; |
| 622 | + if (i == 1 || i == 3) { |
| 623 | + value = null; |
| 624 | + } |
| 625 | + |
| 626 | + XContentBuilder doc = jsonBuilder() |
| 627 | + .startObject() |
| 628 | + .field("tick", i) |
| 629 | + .field("value", value) |
| 630 | + .endObject(); |
| 631 | + client().prepareIndex("movavg_npe", "type").setSource(doc).get(); |
| 632 | + } |
| 633 | + |
| 634 | + refresh(); |
| 635 | + |
| 636 | + SearchResponse response = client() |
| 637 | + .prepareSearch("movavg_npe") |
| 638 | + .addAggregation( |
| 639 | + histogram("histo").field("tick").interval(1) |
| 640 | + .subAggregation(avg("avg").field("value")) |
| 641 | + .subAggregation(movingAvg("movavg", "avg").modelBuilder(new SimpleModel.SimpleModelBuilder()).window(3)) |
| 642 | + .subAggregation(derivative("deriv", "movavg"))).execute().actionGet(); |
| 643 | + |
| 644 | + assertSearchResponse(response); |
| 645 | + } |
| 646 | + |
617 | 647 | private void checkBucketKeyAndDocCount(final String msg, final Histogram.Bucket bucket, final long expectedKey,
|
618 | 648 | final long expectedDocCount) {
|
619 | 649 | assertThat(msg, bucket, notNullValue());
|
|
0 commit comments