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
…4-07-24)

Signed-off-by: GitHub <[email protected]>
  • Loading branch information
dblock authored Jul 24, 2024
1 parent afee32d commit 6965230
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Removed
### Fixed
### Updated APIs
- Updated opensearch-php APIs to reflect [opensearch-api-specification@592b9b6](https://github.com/opensearch-project/opensearch-api-specification/commit/592b9b6d347c688088ce975f52895b7069ab04f1)
### Security
### Dependencies

Expand Down
1 change: 1 addition & 0 deletions src/OpenSearch/Endpoints/Indices/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getParamWhitelist(): array
{
return [
'allow_no_indices',
'cluster_manager_timeout',
'expand_wildcards',
'flat_settings',
'ignore_unavailable',
Expand Down
22 changes: 10 additions & 12 deletions src/OpenSearch/Endpoints/Indices/PutAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

namespace OpenSearch\Endpoints\Indices;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
Expand All @@ -33,19 +32,18 @@ class PutAlias extends AbstractEndpoint

public function getURI(): string
{
if (isset($this->index) !== true) {
throw new RuntimeException(
'index is required for put_alias'
);
$name = $this->name ?? null;
$index = $this->index ?? null;
if (isset($index) && isset($name)) {
return "/$index/_alias/$name";
}
$index = $this->index;
if (isset($this->name) !== true) {
throw new RuntimeException(
'name is required for put_alias'
);
if (isset($index)) {
return "/$index/_alias";
}
$name = $this->name;
return "/$index/_alias/$name";
if (isset($name)) {
return "/_alias/$name";
}
return "/_alias";
}

public function getParamWhitelist(): array
Expand Down
21 changes: 15 additions & 6 deletions src/OpenSearch/Endpoints/Nodes/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@
*/
class Info extends AbstractEndpoint
{
protected $node_id_or_metric;
protected $metric;
protected $node_id;

public function getURI(): string
{
$node_id_or_metric = $this->node_id_or_metric ?? null;
$metric = $this->metric ?? null;
$node_id = $this->node_id ?? null;
if (isset($node_id_or_metric)) {
return "/_nodes/$node_id_or_metric";
}
if (isset($node_id) && isset($metric)) {
return "/_nodes/$node_id/$metric";
}
if (isset($node_id)) {
return "/_nodes/$node_id";
}
if (isset($metric)) {
return "/_nodes/$metric";
}
return "/_nodes";
}

Expand All @@ -65,6 +64,16 @@ public function getMethod(): string
return 'GET';
}

public function setNodeIdOrMetric($node_id_or_metric): Info
{
if (isset($node_id_or_metric) !== true) {
return $this;
}
$this->node_id_or_metric = $node_id_or_metric;

return $this;
}

public function setMetric($metric): Info
{
if (isset($metric) !== true) {
Expand Down
33 changes: 17 additions & 16 deletions src/OpenSearch/Namespaces/IndicesNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,18 +412,19 @@ public function deleteTemplate(array $params = [])
/**
* Returns information about whether a particular index exists.
*
* $params['index'] = (array) Comma-separated list of data streams, indices, and aliases. Supports wildcards (`*`).
* $params['allow_no_indices'] = (boolean) If `false`, the request returns an error if any wildcard expression, index alias, or `_all` value targets only missing or closed indices.This behavior applies even if the request targets other open indices. (Default = false)
* $params['expand_wildcards'] = (any) Type of index that wildcard patterns can match.If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams.Supports comma-separated values, such as `open,hidden`.Valid values are: `all`, `open`, `closed`, `hidden`, `none`.
* $params['flat_settings'] = (boolean) If `true`, returns settings in flat format. (Default = false)
* $params['ignore_unavailable'] = (boolean) If `false`, the request returns an error if it targets a missing or closed index. (Default = false)
* $params['include_defaults'] = (boolean) If `true`, return all default settings in the response. (Default = false)
* $params['local'] = (boolean) If `true`, the request retrieves information from the local node only. (Default = false)
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response.
* $params['human'] = (boolean) Whether to return human readable values for statistics.
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
* $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) Comma-separated list of filters used to reduce the response.
* $params['index'] = (array) Comma-separated list of data streams, indices, and aliases. Supports wildcards (`*`).
* $params['allow_no_indices'] = (boolean) If `false`, the request returns an error if any wildcard expression, index alias, or `_all` value targets only missing or closed indices.This behavior applies even if the request targets other open indices. (Default = false)
* $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node.
* $params['expand_wildcards'] = (any) Type of index that wildcard patterns can match.If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams.Supports comma-separated values, such as `open,hidden`.Valid values are: `all`, `open`, `closed`, `hidden`, `none`.
* $params['flat_settings'] = (boolean) If `true`, returns settings in flat format. (Default = false)
* $params['ignore_unavailable'] = (boolean) If `false`, the request returns an error if it targets a missing or closed index. (Default = false)
* $params['include_defaults'] = (boolean) If `true`, return all default settings in the response. (Default = false)
* $params['local'] = (boolean) If `true`, the request retrieves information from the local node only. (Default = false)
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response.
* $params['human'] = (boolean) Whether to return human readable values for statistics.
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
* $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) Comma-separated list of filters used to reduce the response.
*
* @param array $params Associative array of parameters
* @return bool
Expand Down Expand Up @@ -902,8 +903,8 @@ public function open(array $params = [])
/**
* Creates or updates an alias.
*
* $params['index'] = (array) Comma-separated list of data streams or indices to add. Supports wildcards (`*`). Wildcard patterns that match both data streams and indices return an error. (Required)
* $params['name'] = (string) Alias to update. If the alias doesn't exist, the request creates it. Index alias names support date math. (Required)
* $params['name'] = (string) Alias to update. If the alias doesn't exist, the request creates it. Index alias names support date math.
* $params['index'] = (array) Comma-separated list of data streams or indices to add. Supports wildcards (`*`). Wildcard patterns that match both data streams and indices return an error.
* $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node.
* $params['master_timeout'] = (string) Period to wait for a connection to the master node.If no response is received before the timeout expires, the request fails and returns an error.
* $params['timeout'] = (string) Period to wait for a response.If no response is received before the timeout expires, the request fails and returns an error.
Expand All @@ -919,15 +920,15 @@ public function open(array $params = [])
*/
public function putAlias(array $params = [])
{
$index = $this->extractArgument($params, 'index');
$name = $this->extractArgument($params, 'name');
$index = $this->extractArgument($params, 'index');
$body = $this->extractArgument($params, 'body');

$endpointBuilder = $this->endpoints;
$endpoint = $endpointBuilder('Indices\PutAlias');
$endpoint->setParams($params);
$endpoint->setIndex($index);
$endpoint->setName($name);
$endpoint->setIndex($index);
$endpoint->setBody($body);

return $this->performRequest($endpoint);
Expand Down
21 changes: 12 additions & 9 deletions src/OpenSearch/Namespaces/NodesNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,30 @@ public function hotThreads(array $params = [])
/**
* Returns information about nodes in the cluster.
*
* $params['metric'] = (array) Limits the information returned to the specific metrics. Supports a comma-separated list, such as http,ingest.
* $params['node_id'] = (array) Comma-separated list of node IDs or names used to limit returned information.
* $params['flat_settings'] = (boolean) If true, returns settings in flat format. (Default = false)
* $params['timeout'] = (string) Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response.
* $params['human'] = (boolean) Whether to return human readable values for statistics.
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
* $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) Comma-separated list of filters used to reduce the response.
* $params['node_id_or_metric'] = (any) Limits the information returned to a list of node IDs or specific metrics. Supports a comma-separated list, such as node1,node2 or http,ingest.
* $params['metric'] = (array) Limits the information returned to the specific metrics. Supports a comma-separated list, such as http,ingest.
* $params['node_id'] = (array) Comma-separated list of node IDs or names used to limit returned information.
* $params['flat_settings'] = (boolean) If true, returns settings in flat format. (Default = false)
* $params['timeout'] = (string) Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response.
* $params['human'] = (boolean) Whether to return human readable values for statistics.
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
* $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) Comma-separated list of filters used to reduce the response.
*
* @param array $params Associative array of parameters
* @return array
*/
public function info(array $params = [])
{
$node_id_or_metric = $this->extractArgument($params, 'node_id_or_metric');
$metric = $this->extractArgument($params, 'metric');
$node_id = $this->extractArgument($params, 'node_id');

$endpointBuilder = $this->endpoints;
$endpoint = $endpointBuilder('Nodes\Info');
$endpoint->setParams($params);
$endpoint->setNodeIdOrMetric($node_id_or_metric);
$endpoint->setMetric($metric);
$endpoint->setNodeId($node_id);

Expand Down

0 comments on commit 6965230

Please sign in to comment.