|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ONGR\ElasticsearchDSL\Aggregation; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class representing Histogram aggregation. |
|
18
|
|
|
*/ |
|
19
|
|
|
class DateHistogramAggregation extends AbstractAggregation |
|
20
|
|
|
{ |
|
21
|
|
|
use BucketingTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $interval; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Inner aggregations container init. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $name |
|
32
|
|
|
* @param string $field |
|
33
|
|
|
* @param string $interval |
|
34
|
|
|
* @param array $parameters |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( |
|
37
|
|
|
$name, |
|
38
|
|
|
$field = null, |
|
39
|
|
|
$interval = null, |
|
40
|
|
|
$parameters = [] |
|
41
|
|
|
) { |
|
42
|
|
|
parent::__construct($name); |
|
43
|
|
|
|
|
44
|
|
|
$this->setField($field); |
|
45
|
|
|
$this->setInterval($interval); |
|
46
|
|
|
$this->setParameters($parameters); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return int |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getInterval() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->interval; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $interval |
|
59
|
|
|
*/ |
|
60
|
|
|
public function setInterval($interval) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->interval = $interval; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getType() |
|
69
|
|
|
{ |
|
70
|
|
|
return 'date_histogram'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getArray() |
|
77
|
|
|
{ |
|
78
|
|
|
$out = [ |
|
79
|
|
|
'field' => $this->getField(), |
|
80
|
|
|
'interval' => $this->getInterval(), |
|
81
|
|
|
]; |
|
82
|
|
|
$out = $this->processArray($out); |
|
83
|
|
|
$this->checkRequiredParameters($out); |
|
84
|
|
|
|
|
85
|
|
|
return $out; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Checks if all required parameters are set. |
|
90
|
|
|
* |
|
91
|
|
|
* @param array $data |
|
92
|
|
|
* |
|
93
|
|
|
* @throws \LogicException |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function checkRequiredParameters(array $data) |
|
96
|
|
|
{ |
|
97
|
|
|
if (!$data['field'] || !$data['interval']) { |
|
98
|
|
|
throw new \LogicException('Date histogram aggregation must have field and interval set.'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|