summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Aggregation/AbstractSimpleAggregation.php
blob: 02a0fddbdb47e1c2f8bf0b17be4b8522943bbbcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Elastica\Aggregation;

use Elastica\Script;

abstract class AbstractSimpleAggregation extends AbstractAggregation
{
    /**
     * Set the field for this aggregation.
     *
     * @param string $field the name of the document field on which to perform this aggregation
     *
     * @return $this
     */
    public function setField($field)
    {
        return $this->setParam('field', $field);
    }

    /**
     * Set a script for this aggregation.
     *
     * @param string|Script $script
     *
     * @return $this
     */
    public function setScript($script)
    {
        if ($script instanceof Script) {
            $params = array_merge($this->getParams(), $script->toArray());

            return $this->setParams($params);
        }

        return $this->setParam('script', $script);
    }
}