1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elastica\Aggregation; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class AbstractTermsAggregation. |
7
|
|
|
*/ |
8
|
|
|
abstract class AbstractTermsAggregation extends AbstractSimpleAggregation |
9
|
|
|
{ |
10
|
|
|
public const EXECUTION_HINT_MAP = 'map'; |
11
|
|
|
public const EXECUTION_HINT_GLOBAL_ORDINALS = 'global_ordinals'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Set the minimum number of documents in which a term must appear in order to be returned in a bucket. |
15
|
|
|
*/ |
16
|
|
|
public function setMinimumDocumentCount(int $count): self |
17
|
|
|
{ |
18
|
|
|
return $this->setParam('min_doc_count', $count); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Filter documents to include based on a regular expression. |
23
|
|
|
* |
24
|
|
|
* @See https://www.elastic.co/guide/en/elasticsearch/reference/current/regexp-syntax.html for syntax |
25
|
|
|
* |
26
|
|
|
* @param string $pattern a regular expression, following the Regexp syntax |
27
|
|
|
*/ |
28
|
|
|
public function setInclude(string $pattern): self |
29
|
|
|
{ |
30
|
|
|
return $this->setParam('include', $pattern); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Filter documents to include based on a list of exact values. |
35
|
|
|
* |
36
|
|
|
* @param string[] $values |
37
|
|
|
* |
38
|
|
|
* @See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_exact_values_2 |
39
|
|
|
*/ |
40
|
|
|
public function setIncludeAsExactMatch(array $values): self |
41
|
|
|
{ |
42
|
|
|
return $this->setParam('include', $values); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set the aggregation filter to use partitions. |
47
|
|
|
* |
48
|
|
|
* @See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_partitions |
49
|
|
|
*/ |
50
|
|
|
public function setIncludeWithPartitions(int $partition, int $numPartitions): self |
51
|
|
|
{ |
52
|
|
|
return $this->setParam('include', [ |
53
|
|
|
'partition' => $partition, |
54
|
|
|
'num_partitions' => $numPartitions, |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Filter documents to exclude based on a regular expression. |
60
|
|
|
* |
61
|
|
|
* @param string $pattern a regular expression |
62
|
|
|
*/ |
63
|
|
|
public function setExclude(string $pattern): self |
64
|
|
|
{ |
65
|
|
|
return $this->setParam('exclude', $pattern); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Filter documents to exclude based on a list of exact values. |
70
|
|
|
* |
71
|
|
|
* @param string[] $values |
72
|
|
|
* |
73
|
|
|
* @See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_exact_values_2 |
74
|
|
|
*/ |
75
|
|
|
public function setExcludeAsExactMatch(array $values): self |
76
|
|
|
{ |
77
|
|
|
return $this->setParam('exclude', $values); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Sets the amount of terms to be returned. |
82
|
|
|
*/ |
83
|
|
|
public function setSize(int $size): self |
84
|
|
|
{ |
85
|
|
|
return $this->setParam('size', $size); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Sets how many terms the coordinating node will request from each shard. |
90
|
|
|
*/ |
91
|
|
|
public function setShardSize(int $shardSize): self |
92
|
|
|
{ |
93
|
|
|
return $this->setParam('shard_size', $shardSize); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Instruct Elasticsearch to use direct field data or ordinals of the field values to execute this aggregation. |
98
|
|
|
* The execution hint will be ignored if it is not applicable. |
99
|
|
|
* |
100
|
|
|
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-execution-hint |
101
|
|
|
* |
102
|
|
|
* @param string $hint Execution hint, use one of self::EXECUTION_HINT_MAP or self::EXECUTION_HINT_GLOBAL_ORDINALS |
103
|
|
|
*/ |
104
|
|
|
public function setExecutionHint(string $hint): self |
105
|
|
|
{ |
106
|
|
|
return $this->setParam('execution_hint', $hint); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|