1<?php
2
3namespace Elastica\Aggregation;
4
5/**
6 * Class BucketSelector.
7 *
8 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html
9 */
10class BucketSelector extends AbstractSimpleAggregation
11{
12    /**
13     * @param string      $name
14     * @param array|null  $bucketsPath
15     * @param string|null $script
16     */
17    public function __construct(string $name, array $bucketsPath = null, string $script = null)
18    {
19        parent::__construct($name);
20
21        if (null !== $bucketsPath) {
22            $this->setBucketsPath($bucketsPath);
23        }
24
25        if (null !== $script) {
26            $this->setScript($script);
27        }
28    }
29
30    /**
31     * Set the buckets_path for this aggregation.
32     *
33     * @param array $bucketsPath
34     *
35     * @return $this
36     */
37    public function setBucketsPath($bucketsPath)
38    {
39        return $this->setParam('buckets_path', $bucketsPath);
40    }
41
42    /**
43     * Set the gap policy for this aggregation.
44     *
45     * @param string $gapPolicy
46     *
47     * @return $this
48     */
49    public function setGapPolicy(string $gapPolicy = 'skip')
50    {
51        return $this->setParam('gap_policy', $gapPolicy);
52    }
53}
54