@@ -61,23 +61,29 @@ public function maxChildren(int $maxChildren): self
61
61
62
62
public function toArray (): array
63
63
{
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
+
64
85
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 ,
81
87
];
82
88
}
83
89
}
0 commit comments