diff --git a/CHANGELOG.md b/CHANGELOG.md index 393be22a..fd78e7b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,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@cb320b5](https://github.com/opensearch-project/opensearch-api-specification/commit/cb320b5482551c4f28afa26ff0d1653332699722) ### Security ### Dependencies diff --git a/samples/index.php b/samples/index.php index 570acaeb..b7bb97f8 100644 --- a/samples/index.php +++ b/samples/index.php @@ -19,5 +19,3 @@ $info = $client->info(); echo "{$info['version']['distribution']}: {$info['version']['number']}\n"; - -?> diff --git a/src/OpenSearch/Client.php b/src/OpenSearch/Client.php index a068ba44..e679a65e 100644 --- a/src/OpenSearch/Client.php +++ b/src/OpenSearch/Client.php @@ -38,6 +38,9 @@ use OpenSearch\Namespaces\MonitoringNamespace; use OpenSearch\Namespaces\NodesNamespace; use OpenSearch\Namespaces\NotificationsNamespace; +use OpenSearch\Namespaces\ObservabilityNamespace; +use OpenSearch\Namespaces\PplNamespace; +use OpenSearch\Namespaces\QueryNamespace; use OpenSearch\Namespaces\RemoteStoreNamespace; use OpenSearch\Namespaces\RollupsNamespace; use OpenSearch\Namespaces\SearchPipelineNamespace; @@ -138,6 +141,21 @@ class Client */ protected $notifications; + /** + * @var ObservabilityNamespace + */ + protected $observability; + + /** + * @var PplNamespace + */ + protected $ppl; + + /** + * @var QueryNamespace + */ + protected $query; + /** * @var RemoteStoreNamespace */ @@ -212,6 +230,9 @@ public function __construct(Transport $transport, callable $endpoint, array $reg $this->monitoring = new MonitoringNamespace($transport, $endpoint); $this->nodes = new NodesNamespace($transport, $endpoint); $this->notifications = new NotificationsNamespace($transport, $endpoint); + $this->observability = new ObservabilityNamespace($transport, $endpoint); + $this->ppl = new PplNamespace($transport, $endpoint); + $this->query = new QueryNamespace($transport, $endpoint); $this->remoteStore = new RemoteStoreNamespace($transport, $endpoint); $this->rollups = new RollupsNamespace($transport, $endpoint); $this->searchPipeline = new SearchPipelineNamespace($transport, $endpoint); @@ -1736,6 +1757,27 @@ public function notifications(): NotificationsNamespace { return $this->notifications; } + /** + * Returns the observability namespace + */ + public function observability(): ObservabilityNamespace + { + return $this->observability; + } + /** + * Returns the ppl namespace + */ + public function ppl(): PplNamespace + { + return $this->ppl; + } + /** + * Returns the query namespace + */ + public function query(): QueryNamespace + { + return $this->query; + } /** * Returns the remoteStore namespace */ diff --git a/src/OpenSearch/Endpoints/Indices/Exists.php b/src/OpenSearch/Endpoints/Indices/Exists.php index 9d90b98f..0968b109 100644 --- a/src/OpenSearch/Endpoints/Indices/Exists.php +++ b/src/OpenSearch/Endpoints/Indices/Exists.php @@ -42,6 +42,7 @@ public function getParamWhitelist(): array { return [ 'allow_no_indices', + 'cluster_manager_timeout', 'expand_wildcards', 'flat_settings', 'ignore_unavailable', diff --git a/src/OpenSearch/Endpoints/Indices/PutAlias.php b/src/OpenSearch/Endpoints/Indices/PutAlias.php index a4d28852..62599f4c 100644 --- a/src/OpenSearch/Endpoints/Indices/PutAlias.php +++ b/src/OpenSearch/Endpoints/Indices/PutAlias.php @@ -21,7 +21,6 @@ namespace OpenSearch\Endpoints\Indices; -use OpenSearch\Common\Exceptions\RuntimeException; use OpenSearch\Endpoints\AbstractEndpoint; /** @@ -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 diff --git a/src/OpenSearch/Endpoints/Nodes/Info.php b/src/OpenSearch/Endpoints/Nodes/Info.php index 4d8cca2c..b02a894a 100644 --- a/src/OpenSearch/Endpoints/Nodes/Info.php +++ b/src/OpenSearch/Endpoints/Nodes/Info.php @@ -28,13 +28,18 @@ */ 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"; } @@ -65,6 +70,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) { diff --git a/src/OpenSearch/Endpoints/Observability/CreateObject.php b/src/OpenSearch/Endpoints/Observability/CreateObject.php new file mode 100644 index 00000000..47494884 --- /dev/null +++ b/src/OpenSearch/Endpoints/Observability/CreateObject.php @@ -0,0 +1,55 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Observability/DeleteObject.php b/src/OpenSearch/Endpoints/Observability/DeleteObject.php new file mode 100644 index 00000000..cc600211 --- /dev/null +++ b/src/OpenSearch/Endpoints/Observability/DeleteObject.php @@ -0,0 +1,62 @@ +object_id ?? null; + if (isset($object_id)) { + return "/_plugins/_observability/object/$object_id"; + } + throw new RuntimeException('Missing parameter for the endpoint observability.delete_object'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + public function setObjectId($object_id): DeleteObject + { + if (isset($object_id) !== true) { + return $this; + } + $this->object_id = $object_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Observability/DeleteObjects.php b/src/OpenSearch/Endpoints/Observability/DeleteObjects.php new file mode 100644 index 00000000..e7501edb --- /dev/null +++ b/src/OpenSearch/Endpoints/Observability/DeleteObjects.php @@ -0,0 +1,47 @@ +object_id ?? null; + if (isset($object_id)) { + return "/_plugins/_observability/object/$object_id"; + } + throw new RuntimeException('Missing parameter for the endpoint observability.get_object'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setObjectId($object_id): GetObject + { + if (isset($object_id) !== true) { + return $this; + } + $this->object_id = $object_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Observability/ListObjects.php b/src/OpenSearch/Endpoints/Observability/ListObjects.php new file mode 100644 index 00000000..20e10f55 --- /dev/null +++ b/src/OpenSearch/Endpoints/Observability/ListObjects.php @@ -0,0 +1,45 @@ +object_id ?? null; + if (isset($object_id)) { + return "/_plugins/_observability/object/$object_id"; + } + throw new RuntimeException('Missing parameter for the endpoint observability.update_object'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'PUT'; + } + + public function setBody($body): UpdateObject + { + if (isset($body) !== true) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setObjectId($object_id): UpdateObject + { + if (isset($object_id) !== true) { + return $this; + } + $this->object_id = $object_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ppl/Explain.php b/src/OpenSearch/Endpoints/Ppl/Explain.php new file mode 100644 index 00000000..708526b7 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ppl/Explain.php @@ -0,0 +1,57 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ppl/GetStats.php b/src/OpenSearch/Endpoints/Ppl/GetStats.php new file mode 100644 index 00000000..9c121b95 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ppl/GetStats.php @@ -0,0 +1,47 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ppl/Query.php b/src/OpenSearch/Endpoints/Ppl/Query.php new file mode 100644 index 00000000..bb544c86 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ppl/Query.php @@ -0,0 +1,57 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Query/DatasourceDelete.php b/src/OpenSearch/Endpoints/Query/DatasourceDelete.php new file mode 100644 index 00000000..fac16196 --- /dev/null +++ b/src/OpenSearch/Endpoints/Query/DatasourceDelete.php @@ -0,0 +1,62 @@ +datasource_name ?? null; + if (isset($datasource_name)) { + return "/_plugins/_query/_datasources/$datasource_name"; + } + throw new RuntimeException('Missing parameter for the endpoint query.datasource_delete'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + public function setDatasourceName($datasource_name): DatasourceDelete + { + if (isset($datasource_name) !== true) { + return $this; + } + $this->datasource_name = $datasource_name; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Query/DatasourceRetrieve.php b/src/OpenSearch/Endpoints/Query/DatasourceRetrieve.php new file mode 100644 index 00000000..f45d1adb --- /dev/null +++ b/src/OpenSearch/Endpoints/Query/DatasourceRetrieve.php @@ -0,0 +1,62 @@ +datasource_name ?? null; + if (isset($datasource_name)) { + return "/_plugins/_query/_datasources/$datasource_name"; + } + throw new RuntimeException('Missing parameter for the endpoint query.datasource_retrieve'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setDatasourceName($datasource_name): DatasourceRetrieve + { + if (isset($datasource_name) !== true) { + return $this; + } + $this->datasource_name = $datasource_name; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Query/DatasourcesCreate.php b/src/OpenSearch/Endpoints/Query/DatasourcesCreate.php new file mode 100644 index 00000000..b2a47881 --- /dev/null +++ b/src/OpenSearch/Endpoints/Query/DatasourcesCreate.php @@ -0,0 +1,55 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Query/DatasourcesList.php b/src/OpenSearch/Endpoints/Query/DatasourcesList.php new file mode 100644 index 00000000..16f57529 --- /dev/null +++ b/src/OpenSearch/Endpoints/Query/DatasourcesList.php @@ -0,0 +1,45 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Sql/Close.php b/src/OpenSearch/Endpoints/Sql/Close.php new file mode 100644 index 00000000..2ef15e00 --- /dev/null +++ b/src/OpenSearch/Endpoints/Sql/Close.php @@ -0,0 +1,57 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Sql/Explain.php b/src/OpenSearch/Endpoints/Sql/Explain.php index ef0269ca..6291c3b3 100644 --- a/src/OpenSearch/Endpoints/Sql/Explain.php +++ b/src/OpenSearch/Endpoints/Sql/Explain.php @@ -1,5 +1,7 @@ body = $body; + + return $this; + } } diff --git a/src/OpenSearch/Endpoints/Sql/GetStats.php b/src/OpenSearch/Endpoints/Sql/GetStats.php new file mode 100644 index 00000000..d0992feb --- /dev/null +++ b/src/OpenSearch/Endpoints/Sql/GetStats.php @@ -0,0 +1,47 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Sql/Query.php b/src/OpenSearch/Endpoints/Sql/Query.php index 1ba8170f..c92970e0 100644 --- a/src/OpenSearch/Endpoints/Sql/Query.php +++ b/src/OpenSearch/Endpoints/Sql/Query.php @@ -1,5 +1,7 @@ body = $body; + + return $this; + } } diff --git a/src/OpenSearch/Endpoints/Sql/Settings.php b/src/OpenSearch/Endpoints/Sql/Settings.php new file mode 100644 index 00000000..78289826 --- /dev/null +++ b/src/OpenSearch/Endpoints/Sql/Settings.php @@ -0,0 +1,56 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Namespaces/IndicesNamespace.php b/src/OpenSearch/Namespaces/IndicesNamespace.php index 65d41c1b..7d6b5ca5 100644 --- a/src/OpenSearch/Namespaces/IndicesNamespace.php +++ b/src/OpenSearch/Namespaces/IndicesNamespace.php @@ -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 @@ -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. @@ -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); diff --git a/src/OpenSearch/Namespaces/NodesNamespace.php b/src/OpenSearch/Namespaces/NodesNamespace.php index e9b39043..e9baf762 100644 --- a/src/OpenSearch/Namespaces/NodesNamespace.php +++ b/src/OpenSearch/Namespaces/NodesNamespace.php @@ -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); diff --git a/src/OpenSearch/Namespaces/ObservabilityNamespace.php b/src/OpenSearch/Namespaces/ObservabilityNamespace.php new file mode 100644 index 00000000..3c8132ae --- /dev/null +++ b/src/OpenSearch/Namespaces/ObservabilityNamespace.php @@ -0,0 +1,186 @@ +extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Observability\CreateObject'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** + * Deletes specific observability object specified by ID. + * + * $params['object_id'] = (string) The ID of the Observability Object. + * $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 deleteObject(array $params = []) + { + $object_id = $this->extractArgument($params, 'object_id'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Observability\DeleteObject'); + $endpoint->setParams($params); + $endpoint->setObjectId($object_id); + + return $this->performRequest($endpoint); + } + /** + * Deletes specific observability objects specified by ID or a list of IDs. + * + * $params['objectId'] = (string) The ID of a single Observability Object to delete. + * $params['objectIdList'] = (string) A comma-separated list of Observability Object IDs to delete. + * $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 deleteObjects(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Observability\DeleteObjects'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + /** + * Retrieves Local Stats of all observability objects. + * + * $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 getLocalstats(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Observability\GetLocalstats'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + /** + * Retrieves specific observability object specified by ID. + * + * $params['object_id'] = (string) The ID of the Observability Object. + * $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 getObject(array $params = []) + { + $object_id = $this->extractArgument($params, 'object_id'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Observability\GetObject'); + $endpoint->setParams($params); + $endpoint->setObjectId($object_id); + + return $this->performRequest($endpoint); + } + /** + * Retrieves list of all observability objects. + * + * $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 listObjects(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Observability\ListObjects'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + /** + * Updates an existing observability object. + * + * $params['object_id'] = (string) The ID of the Observability Object. + * $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 updateObject(array $params = []) + { + $object_id = $this->extractArgument($params, 'object_id'); + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Observability\UpdateObject'); + $endpoint->setParams($params); + $endpoint->setObjectId($object_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +} diff --git a/src/OpenSearch/Namespaces/PplNamespace.php b/src/OpenSearch/Namespaces/PplNamespace.php new file mode 100644 index 00000000..e6220a4d --- /dev/null +++ b/src/OpenSearch/Namespaces/PplNamespace.php @@ -0,0 +1,124 @@ +extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Ppl\Explain'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** + * Collect metrics for the plugin within the interval. + * + * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. + * $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results. (Default = true) + * $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 getStats(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Ppl\GetStats'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + /** + * By a stats endpoint, you are able to collect metrics for the plugin within the interval. + * + * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. + * $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results. (Default = true) + * $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 postStats(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Ppl\PostStats'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** + * Send a PPL query to the PPL plugin. + * + * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. + * $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results. (Default = true) + * $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 query(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Ppl\Query'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +} diff --git a/src/OpenSearch/Namespaces/QueryNamespace.php b/src/OpenSearch/Namespaces/QueryNamespace.php new file mode 100644 index 00000000..0ee9a004 --- /dev/null +++ b/src/OpenSearch/Namespaces/QueryNamespace.php @@ -0,0 +1,141 @@ +extractArgument($params, 'datasource_name'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Query\DatasourceDelete'); + $endpoint->setParams($params); + $endpoint->setDatasourceName($datasource_name); + + return $this->performRequest($endpoint); + } + /** + * Retrieves specific datasource specified by name. + * + * $params['datasource_name'] = (string) The Name of the DataSource to retrieve. + * $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 datasourceRetrieve(array $params = []) + { + $datasource_name = $this->extractArgument($params, 'datasource_name'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Query\DatasourceRetrieve'); + $endpoint->setParams($params); + $endpoint->setDatasourceName($datasource_name); + + return $this->performRequest($endpoint); + } + /** + * Creates a new query datasource. + * + * $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 datasourcesCreate(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Query\DatasourcesCreate'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** + * Retrieves list of all datasources. + * + * $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 datasourcesList(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Query\DatasourcesList'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + /** + * Updates an existing query datasource. + * + * $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 datasourcesUpdate(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Query\DatasourcesUpdate'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +} diff --git a/src/OpenSearch/Namespaces/SqlNamespace.php b/src/OpenSearch/Namespaces/SqlNamespace.php index 19285cfb..83340f78 100644 --- a/src/OpenSearch/Namespaces/SqlNamespace.php +++ b/src/OpenSearch/Namespaces/SqlNamespace.php @@ -1,5 +1,7 @@ extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Sql\Close'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** + * Collect metrics for the plugin within the interval. + * + * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. + * $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results (Default = true) + * $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 getStats(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Sql\GetStats'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + /** + * By a stats endpoint, you are able to collect metrics for the plugin within the interval. + * + * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. + * $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results (Default = true) + * $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 postStats(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Sql\PostStats'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** + * Adds SQL settings to the standard OpenSearch cluster settings. + * + * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. + * $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 settings(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Sql\Settings'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } /** + * This API will be removed in a future version. Use 'close' API instead. + * * $params['cursor'] = (string) The cursor given by the server - * $params['fetch_size'] = (int) The fetch size * - * @param array{'query'?: string, 'cursor'?: string, 'fetch_size'?: int} $params Associative array of parameters + * @param array{'cursor': string} $params Associative array of parameters * @return array */ - public function query(array $params): array + public function closeCursor(array $params): array { $endpointBuilder = $this->endpoints; - /** @var AbstractEndpoint $endpoint */ - $endpoint = $endpointBuilder('Sql\Query'); + $endpoint = $endpointBuilder('Sql\Close'); $endpoint->setBody(array_filter([ - 'query' => $this->extractArgument($params, 'query'), 'cursor' => $this->extractArgument($params, 'cursor'), - 'fetch_size' => $this->extractArgument($params, 'fetch_size'), ])); $endpoint->setParams($params); return $this->performRequest($endpoint); - } - - /** + } /** * $params['query'] = (string) The SQL Query * * @param array{'query': string} $params Associative array of parameters * @return array + * + * Note: Use of query parameter is deprecated. Pass it in `body` instead. */ public function explain(array $params): array { $endpointBuilder = $this->endpoints; + $body = $this->extractArgument($params, 'body') ?? []; $query = $this->extractArgument($params, 'query'); - /** @var AbstractEndpoint $endpoint */ $endpoint = $endpointBuilder('Sql\Explain'); - $endpoint->setBody([ + $endpoint->setBody(array_merge($body, [ 'query' => $query, - ]); + ])); $endpoint->setParams($params); return $this->performRequest($endpoint); - } - - /** + } /** + * $params['query'] = (string) The SQL Query + * $params['format'] = (string) The response format * $params['cursor'] = (string) The cursor given by the server + * $params['fetch_size'] = (int) The fetch size * - * @param array{'cursor': string} $params Associative array of parameters + * @param array{'query'?: string, 'cursor'?: string, 'fetch_size'?: int} $params Associative array of parameters * @return array + * + * Note: Use of `query`, `cursor` and `fetch_size` parameters is deprecated. Pass them in `body` instead. + * */ - public function closeCursor(array $params): array + public function query(array $params): array { $endpointBuilder = $this->endpoints; - /** @var AbstractEndpoint $endpoint */ - $endpoint = $endpointBuilder('Sql\CursorClose'); - $endpoint->setBody(array_filter([ + $endpoint = $endpointBuilder('Sql\Query'); + $body = $this->extractArgument($params, 'body') ?? []; + $endpoint->setBody(array_merge($body, array_filter([ + 'query' => $this->extractArgument($params, 'query'), 'cursor' => $this->extractArgument($params, 'cursor'), - ])); + 'fetch_size' => $this->extractArgument($params, 'fetch_size'), + ]))); $endpoint->setParams($params); return $this->performRequest($endpoint); diff --git a/src/OpenSearch/Namespaces/TransformsNamespace.php b/src/OpenSearch/Namespaces/TransformsNamespace.php index 8612685d..55f744df 100644 --- a/src/OpenSearch/Namespaces/TransformsNamespace.php +++ b/src/OpenSearch/Namespaces/TransformsNamespace.php @@ -194,7 +194,7 @@ public function start(array $params = []) return $this->performRequest($endpoint); } /** - * stop transform. + * Stop transform. * * $params['id'] = (string) Transform to stop * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response.