Skip to content

Commit ac07121

Browse files
authored
Merge pull request #74 from summerKK/fix-missing-type-20250803
Fix missing parameter type restrictions in aggregations and sorts
2 parents e72a5d7 + 2bd06e5 commit ac07121

File tree

10 files changed

+43
-31
lines changed

10 files changed

+43
-31
lines changed

src/Aggregations/CardinalityAggregation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function payload(): array
2727
'field' => $this->field,
2828
];
2929

30-
if ($this->missing) {
30+
if ($this->missing !== null) {
3131
$parameters['missing'] = $this->missing;
3232
}
3333

src/Aggregations/Concerns/WithMissing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
trait WithMissing
66
{
7-
protected ?string $missing = null;
7+
protected string|int|float|bool|null $missing = null;
88

9-
public function missing(string $missingValue): self
9+
public function missing(string|int|float|bool $missingValue): self
1010
{
1111
$this->missing = $missingValue;
1212

src/Aggregations/MaxAggregation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function payload(): array
2727
'field' => $this->field,
2828
];
2929

30-
if ($this->missing) {
30+
if ($this->missing !== null) {
3131
$parameters['missing'] = $this->missing;
3232
}
3333

src/Aggregations/MinAggregation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function payload(): array
2727
'field' => $this->field,
2828
];
2929

30-
if ($this->missing) {
30+
if ($this->missing !== null) {
3131
$parameters['missing'] = $this->missing;
3232
}
3333

src/Aggregations/SumAggregation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function payload(): array
2727
'field' => $this->field,
2828
];
2929

30-
if ($this->missing) {
30+
if ($this->missing !== null) {
3131
$parameters['missing'] = $this->missing;
3232
}
3333

src/Aggregations/TermsAggregation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function payload(): array
5353
$parameters['size'] = $this->size;
5454
}
5555

56-
if ($this->missing) {
56+
if ($this->missing !== null) {
5757
$parameters['missing'] = $this->missing;
5858
}
5959

src/Sorts/Concerns/HasMissing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
trait HasMissing
66
{
7-
protected ?string $missing = null;
7+
protected string|int|float|bool|null $missing = null;
88

9-
public function missing(string $missing): static
9+
public function missing(string|int|float|bool $missing): static
1010
{
1111
$this->missing = $missing;
1212

src/Sorts/NestedSort.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,29 @@ public function maxChildren(int $maxChildren): self
6161

6262
public function toArray(): array
6363
{
64+
$payload = array_filter(
65+
[
66+
'order' => $this->order,
67+
'mode' => $this->mode,
68+
'unmapped_type' => $this->unmappedType,
69+
'nested' => array_filter(
70+
[
71+
'path' => $this->path,
72+
'filter' => $this->filter?->toArray(),
73+
'nested' => $this->nested?->toArray(),
74+
'max_children' => $this->maxChildren,
75+
]
76+
),
77+
]
78+
);
79+
80+
// missing can be empty string or zero value
81+
if ($this->missing !== null) {
82+
$payload['missing'] = $this->missing;
83+
}
84+
6485
return [
65-
$this->field => array_filter(
66-
[
67-
'order' => $this->order,
68-
'mode' => $this->mode,
69-
'missing' => $this->missing,
70-
'unmapped_type' => $this->unmappedType,
71-
'nested' => array_filter(
72-
[
73-
'path' => $this->path,
74-
'filter' => $this->filter?->toArray(),
75-
'nested' => $this->nested?->toArray(),
76-
'max_children' => $this->maxChildren,
77-
]
78-
),
79-
]
80-
),
86+
$this->field => $payload,
8187
];
8288
}
8389
}

src/Sorts/Sort.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,22 @@ public function __construct(protected string $field, protected string $order)
2323

2424
public function toArray(): array
2525
{
26-
return [
27-
$this->field => array_filter(
28-
[
26+
$payload = array_filter(
27+
[
2928
'order' => $this->order,
3029
'missing' => $this->missing,
3130
'unmapped_type' => $this->unmappedType,
3231
'mode' => $this->mode,
33-
]
34-
),
32+
]
33+
);
34+
35+
// missing can be empty string or zero value
36+
if ($this->missing !== null) {
37+
$payload['missing'] = $this->missing;
38+
}
39+
40+
return [
41+
$this->field => $payload,
3542
];
3643
}
3744
}

tests/Queries/CollapseTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class CollapseTest extends TestCase
1212
{
13-
1413
private Builder $builder;
1514

1615
private Client $client;

0 commit comments

Comments
 (0)