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\Common\Exceptions\InvalidArgumentException;
19: use OpenSearch\Endpoints\AbstractEndpoint;
20: use OpenSearch\Serializers\SerializerInterface;
21: use Traversable;
22:
23: /**
24: * NOTE: This file is autogenerated using util/GenerateEndpoints.php
25: */
26: class BulkStream extends AbstractEndpoint
27: {
28: public function __construct(SerializerInterface $serializer)
29: {
30: $this->serializer = $serializer;
31: }
32:
33: public function getURI(): string
34: {
35: $index = $this->index ?? null;
36: if (isset($index)) {
37: return "/$index/_bulk/stream";
38: }
39: return "/_bulk/stream";
40: }
41:
42: public function getParamWhitelist(): array
43: {
44: return [
45: '_source',
46: '_source_excludes',
47: '_source_includes',
48: 'batch_interval',
49: 'batch_size',
50: 'pipeline',
51: 'refresh',
52: 'require_alias',
53: 'routing',
54: 'timeout',
55: 'wait_for_active_shards',
56: 'pretty',
57: 'human',
58: 'error_trace',
59: 'source',
60: 'filter_path'
61: ];
62: }
63:
64: public function getMethod(): string
65: {
66: return 'PUT';
67: }
68:
69: public function setBody($body): static
70: {
71: if (isset($body) !== true) {
72: return $this;
73: }
74: if (is_array($body) === true || $body instanceof Traversable) {
75: foreach ($body as $item) {
76: $this->body .= $this->serializer->serialize($item) . "\n";
77: }
78: } elseif (is_string($body)) {
79: $this->body = $body;
80: if (substr($body, -1) != "\n") {
81: $this->body .= "\n";
82: }
83: } else {
84: throw new InvalidArgumentException("Body must be an array, traversable object or string");
85: }
86: return $this;
87: }
88:
89: }
90: