From 52525e1842a72ec7632548009635ec73373d4638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20Jonu=C5=A1as?= <mantas.jonusas@nfq.lt> Date: Tue, 7 Apr 2015 14:40:41 +0300 Subject: [PATCH] Updated extended stats aggregation --- Aggregation/ExtendedStatsAggregation.php | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Aggregation/ExtendedStatsAggregation.php b/Aggregation/ExtendedStatsAggregation.php index 4307db4..110e563 100644 --- a/Aggregation/ExtendedStatsAggregation.php +++ b/Aggregation/ExtendedStatsAggregation.php @@ -56,19 +56,16 @@ class ExtendedStatsAggregation extends AbstractAggregation */ public function getArray() { - $out = []; - - if ($this->getField()) { - $out['field'] = $this->getField(); - } elseif ($this->getScript()) { - $out['script'] = $this->getScript(); - } else { - throw new \LogicException('Extended stats aggregation must have field or script set.'); - } - - if ($this->getSigma()) { - $out['sigma'] = $this->getSigma(); - } + $out = array_filter( + [ + 'field' => $this->getField(), + 'script' => $this->getScript(), + 'sigma' => $this->getSigma(), + ], + function ($val) { + return ($val || is_numeric($val)); + } + ); return $out; } -- GitLab