|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Elastica\Aggregation; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Histogram. |
|
7
|
|
|
* |
|
8
|
|
|
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html |
|
9
|
|
|
*/ |
|
10
|
|
|
class Histogram extends AbstractSimpleAggregation |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param string $name the name of this aggregation |
|
14
|
|
|
* @param string $field the name of the field on which to perform the aggregation |
|
15
|
|
|
* @param int|string $interval the interval by which documents will be bucketed |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct(string $name, string $field, $interval = null) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct($name); |
|
20
|
|
|
$this->setField($field); |
|
21
|
|
|
|
|
22
|
|
|
if (null !== $interval) { |
|
23
|
|
|
trigger_deprecation('ruflin/elastica', '7.1.0', 'The "%s::__construct" third argument is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __CLASS__); |
|
24
|
|
|
|
|
25
|
|
|
$this->setParam('interval', $interval); |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Set the interval by which documents will be bucketed. |
|
31
|
|
|
* |
|
32
|
|
|
* @param int|string $interval |
|
33
|
|
|
* |
|
34
|
|
|
* @return $this |
|
35
|
|
|
*/ |
|
36
|
|
|
public function setInterval($interval): self |
|
37
|
|
|
{ |
|
38
|
|
|
trigger_deprecation('ruflin/elastica', '7.1.0', 'The "%s()" method is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__); |
|
39
|
|
|
|
|
40
|
|
|
return $this->setParam('interval', $interval); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Set the fixed interval by which documents will be bucketed. |
|
45
|
|
|
* |
|
46
|
|
|
* @param int|string $interval |
|
47
|
|
|
* |
|
48
|
|
|
* @return $this |
|
49
|
|
|
*/ |
|
50
|
|
|
public function setFixedInterval($interval): self |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->setParam('fixed_interval', $interval); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Set the calendar interval by which documents will be bucketed. |
|
57
|
|
|
* |
|
58
|
|
|
* @param int|string $interval |
|
59
|
|
|
* |
|
60
|
|
|
* @return $this |
|
61
|
|
|
*/ |
|
62
|
|
|
public function setCalendarInterval($interval): self |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->setParam('calendar_interval', $interval); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Set the bucket sort order. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field |
|
71
|
|
|
* @param string $direction "asc" or "desc" |
|
72
|
|
|
* |
|
73
|
|
|
* @return $this |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setOrder(string $order, string $direction): self |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->setParam('order', [$order => $direction]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Set the minimum number of documents which must fall into a bucket in order for the bucket to be returned. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $count set to 0 to include empty buckets |
|
84
|
|
|
* |
|
85
|
|
|
* @return $this |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setMinimumDocumentCount(int $count): self |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->setParam('min_doc_count', $count); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|