Skip to content
26 changes: 26 additions & 0 deletions DSL/Aggregation/AvgAggregation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\DSL\Aggregation;

/**
* Class representing Avg Aggregation.
*/
class AvgAggregation extends StatsAggregation
{
/**
* {@inheritdoc}
*/
public function getType()
{
return 'avg';
}
}
75 changes: 75 additions & 0 deletions DSL/Aggregation/ExtendedStatsAggregation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\DSL\Aggregation;

use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\MetricTrait;
use ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait;

/**
* Class representing Extended stats aggregation.
*/
class ExtendedStatsAggregation extends AbstractAggregation
{
use MetricTrait;
use ScriptAwareTrait;

/**
* @var int
*/
private $sigma;

/**
* @return int
*/
public function getSigma()
{
return $this->sigma;
}

/**
* @param int $sigma
*/
public function setSigma($sigma)
{
$this->sigma = $sigma;
}

/**
* {@inheritdoc}
*/
public function getType()
{
return 'extended_stats';
}

/**
* {@inheritdoc}
*/
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();
}

return $out;
}
}
26 changes: 26 additions & 0 deletions DSL/Aggregation/MaxAggregation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\DSL\Aggregation;

/**
* Class representing Max Aggregation.
*/
class MaxAggregation extends StatsAggregation
{
/**
* {@inheritdoc}
*/
public function getType()
{
return 'max';
}
}
26 changes: 26 additions & 0 deletions DSL/Aggregation/MinAggregation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\DSL\Aggregation;

/**
* Class representing Min Aggregation.
*/
class MinAggregation extends StatsAggregation
{
/**
* {@inheritdoc}
*/
public function getType()
{
return 'min';
}
}
113 changes: 113 additions & 0 deletions DSL/Aggregation/PercentileRanksAggregation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\DSL\Aggregation;

use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\MetricTrait;
use ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait;

/**
* Class representing Percentile Ranks Aggregation.
*/
class PercentileRanksAggregation extends AbstractAggregation
{
use MetricTrait;
use ScriptAwareTrait;

/**
* @var array
*/
private $values;

/**
* @var int
*/
private $compression;

/**
* @return array
*/
public function getValues()
{
return $this->values;
}

/**
* @param array $values
*/
public function setValues($values)
{
$this->values = $values;
}

/**
* @return int
*/
public function getCompression()
{
return $this->compression;
}

/**
* @param int $compression
*/
public function setCompression($compression)
{
$this->compression = $compression;
}

/**
* {@inheritdoc}
*/
public function getType()
{
return 'percentile_ranks';
}

/**
* {@inheritdoc}
*/
public function getArray()
{
$out = array_filter(
[
'field' => $this->getField(),
'script' => $this->getScript(),
'values' => $this->getValues(),
'compression' => $this->getCompression(),
],
function ($val) {
return ($val || is_numeric($val));
}
);

$this->isRequiredParametersSet($out);

return $out;
}

/**
* @param array $a
*
* @return bool
*
* @throws \LogicException
*/
private function isRequiredParametersSet($a)
{
if (array_key_exists('field', $a) && array_key_exists('values', $a)
|| (array_key_exists('script', $a) && array_key_exists('values', $a))
) {
return true;
}
throw new \LogicException('Percentile ranks aggregation must have field and values or script and values set.');
}
}
108 changes: 108 additions & 0 deletions DSL/Aggregation/PercentilesAggregation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\DSL\Aggregation;

use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\MetricTrait;
use ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait;

/**
* Class representing PercentilesAggregation.
*/
class PercentilesAggregation extends AbstractAggregation
{
use MetricTrait;
use ScriptAwareTrait;

/**
* @var array
*/
private $percents;

/**
* @var int
*/
private $compression;

/**
* @return array
*/
public function getPercents()
{
return $this->percents;
}

/**
* @param array $percents
*/
public function setPercents($percents)
{
$this->percents = $percents;
}

/**
* @return int
*/
public function getCompression()
{
return $this->compression;
}

/**
* @param int $compression
*/
public function setCompression($compression)
{
$this->compression = $compression;
}

/**
* {@inheritdoc}
*/
public function getType()
{
return 'percentiles';
}

/**
* {@inheritdoc}
*/
public function getArray()
{
$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);

return $out;
}

/**
* @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.');
}
}
}
Loading