1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | namespace OpenSearch\Endpoints; |
23: | |
24: | use OpenSearch\Serializers\SerializerInterface; |
25: | |
26: | |
27: | |
28: | |
29: | class Bulk extends AbstractEndpoint |
30: | { |
31: | public function __construct(SerializerInterface $serializer) |
32: | { |
33: | $this->serializer = $serializer; |
34: | } |
35: | |
36: | public function getURI(): string |
37: | { |
38: | $index = $this->index ?? null; |
39: | if (isset($index)) { |
40: | return "/$index/_bulk"; |
41: | } |
42: | return "/_bulk"; |
43: | } |
44: | |
45: | public function getParamWhitelist(): array |
46: | { |
47: | return [ |
48: | '_source', |
49: | '_source_excludes', |
50: | '_source_includes', |
51: | 'pipeline', |
52: | 'refresh', |
53: | 'require_alias', |
54: | 'routing', |
55: | 'timeout', |
56: | 'wait_for_active_shards', |
57: | 'pretty', |
58: | 'human', |
59: | 'error_trace', |
60: | 'source', |
61: | 'filter_path' |
62: | ]; |
63: | } |
64: | |
65: | public function getMethod(): string |
66: | { |
67: | return 'POST'; |
68: | } |
69: | |
70: | public function setBody(string|iterable|null $body): static |
71: | { |
72: | if (is_null($body)) { |
73: | return $this; |
74: | } |
75: | |
76: | if (is_string($body)) { |
77: | if (!str_ends_with($body, "\n")) { |
78: | $body .= "\n"; |
79: | } |
80: | $this->body = $body; |
81: | return $this; |
82: | } |
83: | |
84: | |
85: | foreach ($body as $item) { |
86: | $this->body .= $this->serializer->serialize($item) . "\n"; |
87: | } |
88: | |
89: | return $this; |
90: | } |
91: | |
92: | } |
93: | |