diff --git a/src/Aggregation/Bucketing/DateRangeAggregation.php b/src/Aggregation/Bucketing/DateRangeAggregation.php index 3ca14e29..c5e3f4db 100644 --- a/src/Aggregation/Bucketing/DateRangeAggregation.php +++ b/src/Aggregation/Bucketing/DateRangeAggregation.php @@ -128,17 +128,18 @@ function ($v) { */ public function getArray() { - if ($this->getField() && $this->getFormat() && !empty($this->ranges)) { + if ($this->getField() && !empty($this->ranges)) { $data = [ - 'format' => $this->getFormat(), 'field' => $this->getField(), 'ranges' => $this->ranges, 'keyed' => $this->keyed, ]; - + if ($this->getFormat()) { + $data['format'] = $this->getFormat(); + } return $data; } - throw new \LogicException('Date range aggregation must have field, format set and range added.'); + throw new \LogicException('Date range aggregation must have field and range added.'); } /** diff --git a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php index ca32f902..0e9ca38f 100644 --- a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php @@ -19,7 +19,7 @@ class DateRangeAggregationTest extends \PHPUnit\Framework\TestCase * Test if exception is thrown. * * @expectedException \LogicException - * @expectedExceptionMessage Date range aggregation must have field, format set and range added. + * @expectedExceptionMessage Date range aggregation must have field and range added. */ public function testIfExceptionIsThrownWhenNoParametersAreSet() {