Skip to content

Commit

Permalink
Updated opensearch-php to reflect the latest OpenSearch API spec (202…
Browse files Browse the repository at this point in the history
…5-01-09)

Signed-off-by: GitHub <[email protected]>
  • Loading branch information
dblock authored Jan 9, 2025
1 parent 5855571 commit 762b43e
Show file tree
Hide file tree
Showing 254 changed files with 1,988 additions and 620 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- Fixed PHP 8.4 deprecations
### Updated APIs
- Updated opensearch-php APIs to reflect [opensearch-api-specification@2395cb4](https://github.com/opensearch-project/opensearch-api-specification/commit/2395cb472ec5581656aac184f7b20548cd5b06ac)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@ebe0f8a](https://github.com/opensearch-project/opensearch-api-specification/commit/ebe0f8a885f7db7e882d160c101055a5aa70a707)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@398481e](https://github.com/opensearch-project/opensearch-api-specification/commit/398481e5bd1cc590d947c35379c47096f2114f00)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@6bb1fed](https://github.com/opensearch-project/opensearch-api-specification/commit/6bb1fed0a2c7cf094a5ecfdb01f0306a4b9f8eba)
Expand Down
40 changes: 17 additions & 23 deletions src/OpenSearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

namespace OpenSearch;

use OpenSearch\Common\Exceptions\BadMethodCallException;
use OpenSearch\Common\Exceptions\NoNodesAvailableException;
use OpenSearch\Endpoints\AbstractEndpoint;
use OpenSearch\Namespaces\NamespaceBuilderInterface;
use OpenSearch\Namespaces\BooleanRequestWrapper;
use OpenSearch\Namespaces\NamespaceBuilderInterface;
use OpenSearch\Namespaces\AsyncSearchNamespace;
use OpenSearch\Namespaces\AsynchronousSearchNamespace;
use OpenSearch\Namespaces\CatNamespace;
Expand Down Expand Up @@ -59,7 +57,6 @@
use OpenSearch\Namespaces\TasksNamespace;
use OpenSearch\Namespaces\TransformsNamespace;
use OpenSearch\Namespaces\WlmNamespace;
use OpenSearch\Traits\DeprecatedPropertyTrait;

/**
* Class Client
Expand All @@ -72,6 +69,8 @@ class Client

/**
* @var Transport
*
* @deprecated in 2.3.2 and will be removed in 3.0.0.
*/
public $transport;

Expand Down Expand Up @@ -265,7 +264,7 @@ class Client
/**
* Client constructor
*
* @param \OpenSearch\TransportInterface|\OpenSearch\Transport $transport
* @param TransportInterface|Transport $transport
* @param callable|EndpointFactoryInterface $endpointFactory
* @param NamespaceBuilderInterface[] $registeredNamespaces
*/
Expand Down Expand Up @@ -726,7 +725,7 @@ public function exists(array $params = []): bool
$endpoint->setId($id);
$endpoint->setIndex($index);

return BooleanRequestWrapper::performRequest($endpoint, $this->transport);
return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport);
}

/**
Expand Down Expand Up @@ -765,7 +764,7 @@ public function existsSource(array $params = []): bool
$endpoint->setId($id);
$endpoint->setIndex($index);

return BooleanRequestWrapper::performRequest($endpoint, $this->transport);
return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport);
}

/**
Expand Down Expand Up @@ -1222,7 +1221,7 @@ public function ping(array $params = []): bool
$endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ping::class);
$endpoint->setParams($params);

return BooleanRequestWrapper::performRequest($endpoint, $this->transport);
return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport);
}

/**
Expand Down Expand Up @@ -1322,7 +1321,7 @@ public function reindex(array $params = [])
}

/**
* Changes the number of requests per second for a particular Reindex operation.
* Changes the number of requests per second for a particular reindex operation.
*
* $params['task_id'] = (string) Identifier for the task. (Required)
* $params['requests_per_second'] = (number) The throttle for this request in sub-requests per second.
Expand Down Expand Up @@ -1408,7 +1407,6 @@ public function scriptsPainlessExecute(array $params = [])
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false)
* $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
* $params['filter_path'] = (any) Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with "-".
* $params['body'] = (array) The scroll ID if not passed by URL or query parameter.
*
* @param array $params Associative array of parameters
* @return array
Expand Down Expand Up @@ -2040,14 +2038,14 @@ protected function getEndpointFactory(): EndpointFactoryInterface
* Catchall for registered namespaces
*
* @return object
* @throws BadMethodCallException if the namespace cannot be found
* @throws \BadMethodCallException if the namespace cannot be found
*/
public function __call(string $name, array $arguments)
{
if (isset($this->registeredNamespaces[$name])) {
return $this->registeredNamespaces[$name];
}
throw new BadMethodCallException("Namespace [$name] not found");
throw new \BadMethodCallException("Namespace [$name] not found");
}

/**
Expand All @@ -2070,9 +2068,9 @@ public function extractArgument(array &$params, string $arg)
}

/**
* Sends a raw request to the cluster
* @return array|string|null
* @throws \Exception
* Send a raw request to the cluster.
*
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public function request(string $method, string $uri, array $attributes = []): array|string|null
{
Expand All @@ -2084,23 +2082,19 @@ public function request(string $method, string $uri, array $attributes = []): ar
}

/**
* Sends a request for the given endpoint.
*
* @param \OpenSearch\Endpoints\AbstractEndpoint $endpoint
* Send a request for an endpoint.
*
* @return array|string|null
*
* @throws \Exception
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
private function performRequest(AbstractEndpoint $endpoint): array|string|null
{
$options = $endpoint->getOptions();
return $this->httpTransport->sendRequest(
$endpoint->getMethod(),
$endpoint->getURI(),
$endpoint->getParams(),
$endpoint->getBody(),
$options['headers'] ?? []
$endpoint->getOptions()
);
}

}
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AsynchronousSearch/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand Down
24 changes: 13 additions & 11 deletions src/OpenSearch/Endpoints/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,25 @@ public function getMethod(): string
return 'POST';
}

public function setBody($body): static
public function setBody(string|iterable|null $body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
if (is_array($body) === true || $body instanceof Traversable) {
foreach ($body as $item) {
$this->body .= $this->serializer->serialize($item) . "\n";

if (is_string($body)) {
if (!str_ends_with($body, "\n")) {
$body .= "\n";
}
} elseif (is_string($body)) {
$this->body = $body;
if (substr($body, -1) != "\n") {
$this->body .= "\n";
}
} else {
throw new InvalidArgumentException("Body must be an array, traversable object or string");
return $this;
}

// Must be an iterable.
foreach ($body as $item) {
$this->body .= $this->serializer->serialize($item) . "\n";
}

return $this;
}

Expand Down
24 changes: 13 additions & 11 deletions src/OpenSearch/Endpoints/BulkStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,25 @@ public function getMethod(): string
return 'PUT';
}

public function setBody($body): static
public function setBody(string|iterable|null $body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
if (is_array($body) === true || $body instanceof Traversable) {
foreach ($body as $item) {
$this->body .= $this->serializer->serialize($item) . "\n";

if (is_string($body)) {
if (!str_ends_with($body, "\n")) {
$body .= "\n";
}
} elseif (is_string($body)) {
$this->body = $body;
if (substr($body, -1) != "\n") {
$this->body .= "\n";
}
} else {
throw new InvalidArgumentException("Body must be an array, traversable object or string");
return $this;
}

// Must be an iterable.
foreach ($body as $item) {
$this->body .= $this->serializer->serialize($item) . "\n";
}

return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cat/PitSegments.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cat/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getMethod(): string

public function setName($name): static
{
if (isset($name) !== true) {
if (is_null($name)) {
return $this;
}
$this->name = $name;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/ClearScroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/AllocationExplain.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getMethod(): string

public function setName($name): static
{
if (isset($name) !== true) {
if (is_null($name)) {
return $this;
}
$this->name = $name;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/DeleteWeightedRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getMethod(): string

public function setName($name): static
{
if (isset($name) !== true) {
if (is_null($name)) {
return $this;
}
$this->name = $name;
Expand Down
1 change: 1 addition & 0 deletions src/OpenSearch/Endpoints/Cluster/GetComponentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function getParamWhitelist(): array
{
return [
'cluster_manager_timeout',
'flat_settings',
'local',
'master_timeout',
'pretty',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getMethod(): string

public function setAwarenessAttributeName($awareness_attribute_name): static
{
if (isset($awareness_attribute_name) !== true) {
if (is_null($awareness_attribute_name)) {
return $this;
}
$this->awareness_attribute_name = $awareness_attribute_name;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/GetWeightedRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getMethod(): string

public function setAttribute($attribute): static
{
if (isset($attribute) !== true) {
if (is_null($attribute)) {
return $this;
}
$this->attribute = $attribute;
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSearch/Endpoints/Cluster/PutComponentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand All @@ -72,7 +72,7 @@ public function setBody($body): static

public function setName($name): static
{
if (isset($name) !== true) {
if (is_null($name)) {
return $this;
}
$this->name = $name;
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSearch/Endpoints/Cluster/PutDecommissionAwareness.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getMethod(): string

public function setAwarenessAttributeName($awareness_attribute_name): static
{
if (isset($awareness_attribute_name) !== true) {
if (is_null($awareness_attribute_name)) {
return $this;
}
$this->awareness_attribute_name = $awareness_attribute_name;
Expand All @@ -64,7 +64,7 @@ public function setAwarenessAttributeName($awareness_attribute_name): static

public function setAwarenessAttributeValue($awareness_attribute_value): static
{
if (isset($awareness_attribute_value) !== true) {
if (is_null($awareness_attribute_value)) {
return $this;
}
$this->awareness_attribute_value = $awareness_attribute_value;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/PutSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSearch/Endpoints/Cluster/PutWeightedRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand All @@ -62,7 +62,7 @@ public function setBody($body): static

public function setAttribute($attribute): static
{
if (isset($attribute) !== true) {
if (is_null($attribute)) {
return $this;
}
$this->attribute = $attribute;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Cluster/Reroute.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getMethod(): string

public function setBody($body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
$this->body = $body;
Expand Down
Loading

0 comments on commit 762b43e

Please sign in to comment.