1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * SPDX-License-Identifier: Apache-2.0
7: *
8: * The OpenSearch Contributors require contributions made to
9: * this file be licensed under the Apache-2.0 license or a
10: * compatible open source license.
11: *
12: * Modifications Copyright OpenSearch Contributors. See
13: * GitHub history for details.
14: */
15:
16: namespace OpenSearch\Endpoints;
17:
18: use OpenSearch\Serializers\SerializerInterface;
19:
20: /**
21: * NOTE: This file is autogenerated using util/GenerateEndpoints.php
22: */
23: class BulkStream extends AbstractEndpoint
24: {
25: public function __construct(SerializerInterface $serializer)
26: {
27: $this->serializer = $serializer;
28: }
29:
30: public function getURI(): string
31: {
32: $index = $this->index ?? null;
33: if (isset($index)) {
34: return "/$index/_bulk/stream";
35: }
36: return "/_bulk/stream";
37: }
38:
39: public function getParamWhitelist(): array
40: {
41: return [
42: '_source',
43: '_source_excludes',
44: '_source_includes',
45: 'batch_interval',
46: 'batch_size',
47: 'pipeline',
48: 'refresh',
49: 'require_alias',
50: 'routing',
51: 'timeout',
52: 'wait_for_active_shards',
53: 'pretty',
54: 'human',
55: 'error_trace',
56: 'source',
57: 'filter_path'
58: ];
59: }
60:
61: public function getMethod(): string
62: {
63: return 'PUT';
64: }
65:
66: public function setBody(string|iterable|null $body): static
67: {
68: if (is_null($body)) {
69: return $this;
70: }
71:
72: if (is_string($body)) {
73: if (!str_ends_with($body, "\n")) {
74: $body .= "\n";
75: }
76: $this->body = $body;
77: return $this;
78: }
79:
80: // Must be an iterable.
81: foreach ($body as $item) {
82: $this->body .= $this->serializer->serialize($item) . "\n";
83: }
84:
85: return $this;
86: }
87:
88: }
89: