diff --git a/src/Aggregation/Pipeline/BucketScriptAggregation.php b/src/Aggregation/Pipeline/BucketScriptAggregation.php new file mode 100644 index 0000000000000000000000000000000000000000..ac1d90ac343119dbf9cd040883963c95082a6d6f --- /dev/null +++ b/src/Aggregation/Pipeline/BucketScriptAggregation.php @@ -0,0 +1,82 @@ +<?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\ElasticsearchDSL\Aggregation\Pipeline; + +/** + * Class representing Bucket Script Pipeline Aggregation. + * + * @link https://goo.gl/miVxcx + */ +class BucketScriptAggregation extends AbstractPipelineAggregation +{ + /** + * @var string + */ + private $script; + + /** + * @param string $name + * @param array $bucketsPath + * @param string $script + */ + public function __construct($name, $bucketsPath, $script = null) + { + parent::__construct($name, $bucketsPath); + $this->setScript($script); + } + + /** + * @return string + */ + public function getScript() + { + return $this->script; + } + + /** + * @param string $script + */ + public function setScript($script) + { + $this->script = $script; + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'bucket_script'; + } + + /** + * {@inheritdoc} + */ + public function getArray() + { + if (!$this->getScript()) { + throw new \LogicException( + sprintf( + '`%s` aggregation must have script set.', + $this->getName() + ) + ); + } + + $out = [ + 'buckets_path' => $this->getBucketsPath(), + 'script' => $this->getScript(), + ]; + + return $out; + } +}