From 439a83e3be026d8ee1cf6234b1f9ed13b18a1ee7 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Mon, 27 Mar 2023 10:05:00 +0200 Subject: [PATCH] Updated APIs to 8.7 --- src/Endpoints/Ml.php | 46 +++++++++++++++++++++++++++-- src/Endpoints/Transform.php | 43 +++++++++++++++++++++++++-- src/Traits/ClientEndpointsTrait.php | 40 +++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 5 deletions(-) diff --git a/src/Endpoints/Ml.php b/src/Endpoints/Ml.php index eeee93988..47bba93de 100644 --- a/src/Endpoints/Ml.php +++ b/src/Endpoints/Ml.php @@ -411,6 +411,7 @@ public function deleteForecast(array $params = []) * job_id: string, // (REQUIRED) The ID of the job to delete * force: boolean, // True if the job should be forcefully deleted * wait_for_completion: boolean, // Should this request wait until the operation has completed before returning + * delete_user_annotations: boolean, // Should annotations added by the user be deleted * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) * human: boolean, // Return human readable values for statistics. (DEFAULT: true) * error_trace: boolean, // Include the stack trace of returned errors. (DEFAULT: false) @@ -431,7 +432,7 @@ public function deleteJob(array $params = []) $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']); $method = 'DELETE'; - $url = $this->addQueryString($url, $params, ['force','wait_for_completion','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['force','wait_for_completion','delete_user_annotations','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', ]; @@ -2186,6 +2187,7 @@ public function putTrainedModelVocabulary(array $params = []) * @param array{ * job_id: string, // (REQUIRED) The ID of the job to reset * wait_for_completion: boolean, // Should this request wait until the operation has completed before returning + * delete_user_annotations: boolean, // Should annotations added by the user be deleted * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) * human: boolean, // Return human readable values for statistics. (DEFAULT: true) * error_trace: boolean, // Include the stack trace of returned errors. (DEFAULT: false) @@ -2206,7 +2208,7 @@ public function resetJob(array $params = []) $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_reset'; $method = 'POST'; - $url = $this->addQueryString($url, $params, ['wait_for_completion','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['wait_for_completion','delete_user_annotations','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', ]; @@ -2375,6 +2377,7 @@ public function startDatafeed(array $params = []) * cache_size: string, // A byte-size value for configuring the inference cache size. For example, 20mb. * number_of_allocations: int, // The total number of allocations this model is assigned across machine learning nodes. * threads_per_allocation: int, // The number of threads used by each model allocation during inference. + * priority: string, // The deployment priority. * queue_capacity: int, // Controls how many inference requests are allowed in the queue at a time. * timeout: time, // Controls the amount of time to wait for the model to deploy. * wait_for: string, // The allocation status for which to wait @@ -2398,7 +2401,7 @@ public function startTrainedModelDeployment(array $params = []) $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/deployment/_start'; $method = 'POST'; - $url = $this->addQueryString($url, $params, ['cache_size','number_of_allocations','threads_per_allocation','queue_capacity','timeout','wait_for','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['cache_size','number_of_allocations','threads_per_allocation','priority','queue_capacity','timeout','wait_for','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', @@ -2717,6 +2720,43 @@ public function updateModelSnapshot(array $params = []) } + /** + * Updates certain properties of trained model deployment. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/update-trained-model-deployment.html + * + * @param array{ + * model_id: string, // (REQUIRED) The unique identifier of the trained model. + * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) + * human: boolean, // Return human readable values for statistics. (DEFAULT: true) + * error_trace: boolean, // Include the stack trace of returned errors. (DEFAULT: false) + * source: string, // The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * filter_path: list, // A comma-separated list of filters used to reduce the response. + * body: array, // (REQUIRED) The updated trained model deployment settings + * } $params + * + * @throws MissingParameterException if a required parameter is missing + * @throws NoNodeAvailableException if all the hosts are offline + * @throws ClientResponseException if the status code of response is 4xx + * @throws ServerResponseException if the status code of response is 5xx + * + * @return Elasticsearch|Promise + */ + public function updateTrainedModelDeployment(array $params = []) + { + $this->checkRequiredParameters(['model_id','body'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/deployment/_update'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + /** * Upgrades a given job snapshot to the current major version. * diff --git a/src/Endpoints/Transform.php b/src/Endpoints/Transform.php index 1e473f7fc..a809fe099 100644 --- a/src/Endpoints/Transform.php +++ b/src/Endpoints/Transform.php @@ -115,6 +115,7 @@ public function getTransform(array $params = []) * transform_id: string, // (REQUIRED) The id of the transform for which to get stats. '_all' or '*' implies all transforms * from: number, // skips a number of transform stats, defaults to 0 * size: number, // specifies a max number of transform stats to get, defaults to 100 + * timeout: time, // Controls the time to wait for the stats * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified) * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) * human: boolean, // Return human readable values for statistics. (DEFAULT: true) @@ -136,7 +137,7 @@ public function getTransformStats(array $params = []) $url = '/_transform/' . $this->encode($params['transform_id']) . '/_stats'; $method = 'GET'; - $url = $this->addQueryString($url, $params, ['from','size','allow_no_match','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['from','size','timeout','allow_no_match','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', ]; @@ -260,6 +261,43 @@ public function resetTransform(array $params = []) } + /** + * Schedules now a transform. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/schedule-now-transform.html + * + * @param array{ + * transform_id: string, // (REQUIRED) The id of the transform. + * timeout: time, // Controls the time to wait for the scheduling to take place + * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) + * human: boolean, // Return human readable values for statistics. (DEFAULT: true) + * error_trace: boolean, // Include the stack trace of returned errors. (DEFAULT: false) + * source: string, // The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * filter_path: list, // A comma-separated list of filters used to reduce the response. + * } $params + * + * @throws MissingParameterException if a required parameter is missing + * @throws NoNodeAvailableException if all the hosts are offline + * @throws ClientResponseException if the status code of response is 4xx + * @throws ServerResponseException if the status code of response is 5xx + * + * @return Elasticsearch|Promise + */ + public function scheduleNowTransform(array $params = []) + { + $this->checkRequiredParameters(['transform_id'], $params); + $url = '/_transform/' . $this->encode($params['transform_id']) . '/_schedule_now'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + /** * Starts one or more transforms. * @@ -267,6 +305,7 @@ public function resetTransform(array $params = []) * * @param array{ * transform_id: string, // (REQUIRED) The id of the transform to start + * from: string, // Restricts the set of transformed entities to those changed after this time * timeout: time, // Controls the time to wait for the transform to start * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) * human: boolean, // Return human readable values for statistics. (DEFAULT: true) @@ -288,7 +327,7 @@ public function startTransform(array $params = []) $url = '/_transform/' . $this->encode($params['transform_id']) . '/_start'; $method = 'POST'; - $url = $this->addQueryString($url, $params, ['timeout','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['from','timeout','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', ]; diff --git a/src/Traits/ClientEndpointsTrait.php b/src/Traits/ClientEndpointsTrait.php index ac2ed6123..875a53bd1 100644 --- a/src/Traits/ClientEndpointsTrait.php +++ b/src/Traits/ClientEndpointsTrait.php @@ -813,6 +813,46 @@ public function getSource(array $params = []) } + /** + * Returns the health of the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/health-api.html + * + * @param array{ + * feature: string, // A feature of the cluster, as returned by the top-level health API + * timeout: time, // Explicit operation timeout + * verbose: boolean, // Opt in for more information about the health of the system + * size: int, // Limit the number of affected resources the health API returns + * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) + * human: boolean, // Return human readable values for statistics. (DEFAULT: true) + * error_trace: boolean, // Include the stack trace of returned errors. (DEFAULT: false) + * source: string, // The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * filter_path: list, // A comma-separated list of filters used to reduce the response. + * } $params + * + * @throws NoNodeAvailableException if all the hosts are offline + * @throws ClientResponseException if the status code of response is 4xx + * @throws ServerResponseException if the status code of response is 5xx + * + * @return Elasticsearch|Promise + */ + public function healthReport(array $params = []) + { + if (isset($params['feature'])) { + $url = '/_health_report/' . $this->encode($params['feature']); + $method = 'GET'; + } else { + $url = '/_health_report'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['timeout','verbose','size','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + /** * Creates or updates a document in an index. *