1<?php
2
3namespace Elastica\Aggregation;
4
5/**
6 * Class GeotileGridAggregation.
7 *
8 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geotilegrid-aggregation.html
9 */
10class GeotileGridAggregation extends AbstractAggregation
11{
12    use Traits\ShardSizeTrait;
13
14    public const DEFAULT_PRECISION_VALUE = 7;
15    public const DEFAULT_SIZE_VALUE = 10000;
16
17    /**
18     * @param string $name  the name of this aggregation
19     * @param string $field the field on which to perform this aggregation
20     */
21    public function __construct(string $name, string $field)
22    {
23        parent::__construct($name);
24        $this->setField($field);
25    }
26
27    /**
28     * Set the field for this aggregation.
29     *
30     * @param string $field the name of the document field on which to perform this aggregation
31     *
32     * @return $this
33     */
34    public function setField(string $field): self
35    {
36        return $this->setParam('field', $field);
37    }
38
39    /**
40     * Set the precision for this aggregation.
41     *
42     * @param int $precision an integer between 1 and 12, inclusive. Defaults to 5.
43     *
44     * @return $this
45     */
46    public function setPrecision(int $precision): self
47    {
48        return $this->setParam('precision', $precision);
49    }
50
51    /**
52     * Set the maximum number of buckets to return.
53     *
54     * @param int $size defaults to 10,000
55     *
56     * @return $this
57     */
58    public function setSize(int $size): self
59    {
60        return $this->setParam('size', $size);
61    }
62}
63