Skip to content

Commit 108e494

Browse files
committed
Term aggregation can have key
1 parent 02b13ff commit 108e494

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Aggregation/Term.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,29 @@ class Term implements LeafAggregationInterface
2424
*/
2525
private $missing;
2626

27+
/**
28+
* @var string
29+
*/
30+
private $key;
31+
2732

2833
public function __construct(
2934
string $field
3035
, int $size = 5
3136
, int $missing = NULL
37+
, string $key = NULL
3238
)
3339
{
3440
$this->field = $field;
3541
$this->size = $size;
3642
$this->missing = $missing;
43+
$this->key = $key;
3744
}
3845

3946

4047
public function key() : string
4148
{
42-
return $this->field;
49+
return $this->key ?: $this->field;
4350
}
4451

4552

@@ -55,7 +62,9 @@ public function toArray() : array
5562
}
5663

5764
return [
58-
'terms' => $array,
65+
$this->key => [
66+
'terms' => $array,
67+
],
5968
];
6069
}
6170

0 commit comments

Comments
 (0)