Skip to content
Snippets Groups Projects
Commit f86ec104 authored by Mantas Jonušas's avatar Mantas Jonušas
Browse files

Refactored percentiles aggregation

parent 32952edf
No related branches found
No related tags found
No related merge requests found
......@@ -77,24 +77,32 @@ class PercentilesAggregation extends AbstractAggregation
*/
public function getArray()
{
$out = [];
$out = array_filter(
[
'compression' => $this->getCompression(),
'percents' => $this->getPercents(),
'field' => $this->getField(),
'script' => $this->getScript(),
],
function ($val) {
return ($val || is_numeric($val));
}
);
$this->isRequiredParametersSet($out);
if ($this->getField()) {
$out['field'] = $this->getField();
} elseif ($this->getScript()) {
$out['script'] = $this->getScript();
} else {
throw new \LogicException('Percentiles aggregation must have field or script set.');
}
if ($this->getCompression()) {
$out['compression'] = $this->getCompression();
}
return $out;
}
if ($this->getPercents()) {
$out['percents'] = $this->getPercents();
/**
* @param array $a
*
* @throws \LogicException
*/
private function isRequiredParametersSet($a)
{
if (!array_key_exists('field', $a) && !array_key_exists('script', $a)) {
throw new \LogicException('Percentiles aggregation must have field or script set.');
}
return $out;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment