From 4c175d5c90007bbb7908ce40ef94cb64db1d907c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mantas=20Marcinkevi=C4=8Dius?= <marc.mantas@gmail.com>
Date: Mon, 29 Aug 2016 14:09:27 +0300
Subject: [PATCH] added bucket script aggregation

---
 .../Pipeline/BucketScriptAggregation.php      | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 src/Aggregation/Pipeline/BucketScriptAggregation.php

diff --git a/src/Aggregation/Pipeline/BucketScriptAggregation.php b/src/Aggregation/Pipeline/BucketScriptAggregation.php
new file mode 100644
index 0000000..ac1d90a
--- /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;
+    }
+}
-- 
GitLab