Skip to content
Snippets Groups Projects
Commit 1d74bb2c authored by Martynas Sudintas's avatar Martynas Sudintas
Browse files

cardinality aggregation now must have field or script set

parent 3f255c46
No related branches found
No related tags found
No related merge requests found
......@@ -30,21 +30,31 @@ class CardinalityAggregation extends AbstractAggregation
*/
private $rehash;
/**
* @var string
*/
private $script;
/**
* {@inheritdoc}
*/
public function getArray()
{
if (!$this->getField()) {
return new \stdClass();
$out = [];
if ($this->getField()) {
$out['field'] = $this->getField();
} elseif ($this->getScript()) {
$out['script'] = $this->getScript();
} else {
throw new \LogicException('Cardinality aggregation must have field or script set.');
}
$out['field'] = $this->getField();
if ($this->getPrecisionThreshold()) {
$out['precision_threshold'] = $this->getPrecisionThreshold();
}
if ($this->isRehash() !== null) {
if ($this->isRehash()) {
$out['rehash'] = $this->isRehash();
}
......@@ -85,6 +95,22 @@ class CardinalityAggregation extends AbstractAggregation
$this->rehash = $rehash;
}
/**
* @return string
*/
public function getScript()
{
return $this->script;
}
/**
* @param string $script
*/
public function setScript($script)
{
$this->script = $script;
}
/**
* {@inheritdoc}
*/
......
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