Newer
Older
<?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;
/**
* Difference values counter.
*/
class CardinalityAggregation extends AbstractAggregation
{
use MetricTrait;
/**
* @var int
*/
private $precisionThreshold;
/**
* @var bool
*/
private $rehash;
/**
* {@inheritdoc}
*/
public function getArray()
{
$out = array_filter(
[
'field' => $this->getField(),
'script' => $this->getScript(),
'precision_threshold' => $this->getPrecisionThreshold(),
'rehash' => $this->isRehash(),
],
function ($val) {
return ($val || is_bool($val));
}
);
$this->checkRequiredFields($out);
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
return $out;
}
/**
* Precision threshold.
*
* @param int $precision Precision Threshold.
*/
public function setPrecisionThreshold($precision)
{
$this->precisionThreshold = $precision;
}
/**
* @return int
*/
public function getPrecisionThreshold()
{
return $this->precisionThreshold;
}
/**
* @return bool
*/
public function isRehash()
{
return $this->rehash;
}
/**
* @param bool $rehash
*/
public function setRehash($rehash)
{
$this->rehash = $rehash;
}
* Checks if required fields are set.
*
* @param array $fields
*
* @throws \LogicException
private function checkRequiredFields($fields)
if (!array_key_exists('field', $fields) && !array_key_exists('script', $fields)) {
throw new \LogicException('Cardinality aggregation must have field or script set.');
}