| @@ 22-46 (lines=25) @@ | ||
| 19 | /** |
|
| 20 | * @group functional |
|
| 21 | */ |
|
| 22 | public function testDateHistogramAggregation(): void |
|
| 23 | { |
|
| 24 | $this->_checkVersion('7.2'); |
|
| 25 | ||
| 26 | $agg = new DateHistogram('hist', 'created'); |
|
| 27 | $agg->setFixedInterval('1h'); |
|
| 28 | ||
| 29 | $query = new Query(); |
|
| 30 | $query->addAggregation($agg); |
|
| 31 | $results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); |
|
| 32 | ||
| 33 | $docCount = 0; |
|
| 34 | $nonDocCount = 0; |
|
| 35 | foreach ($results['buckets'] as $bucket) { |
|
| 36 | if (1 == $bucket['doc_count']) { |
|
| 37 | ++$docCount; |
|
| 38 | } else { |
|
| 39 | ++$nonDocCount; |
|
| 40 | } |
|
| 41 | } |
|
| 42 | // 3 Documents that were added |
|
| 43 | $this->assertEquals(3, $docCount); |
|
| 44 | // 1 document that was generated in between for the missing hour |
|
| 45 | $this->assertEquals(1, $nonDocCount); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @group unit |
|
| @@ 74-98 (lines=25) @@ | ||
| 71 | /** |
|
| 72 | * @group functional |
|
| 73 | */ |
|
| 74 | public function testDateHistogramCalendarAggregation(): void |
|
| 75 | { |
|
| 76 | $this->_checkVersion('7.2'); |
|
| 77 | ||
| 78 | $agg = new DateHistogram('hist', 'created'); |
|
| 79 | $agg->setCalendarInterval('1h'); |
|
| 80 | ||
| 81 | $query = new Query(); |
|
| 82 | $query->addAggregation($agg); |
|
| 83 | $results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); |
|
| 84 | ||
| 85 | $docCount = 0; |
|
| 86 | $nonDocCount = 0; |
|
| 87 | foreach ($results['buckets'] as $bucket) { |
|
| 88 | if (1 == $bucket['doc_count']) { |
|
| 89 | ++$docCount; |
|
| 90 | } else { |
|
| 91 | ++$nonDocCount; |
|
| 92 | } |
|
| 93 | } |
|
| 94 | // 3 Documents that were added |
|
| 95 | $this->assertEquals(3, $docCount); |
|
| 96 | // 1 document that was generated in between for the missing hour |
|
| 97 | $this->assertEquals(1, $nonDocCount); |
|
| 98 | } |
|
| 99 | ||
| 100 | /** |
|
| 101 | * @group unit |
|