diff --git a/Elastic/Elasticsearch/Client.php b/Elastic/Elasticsearch/Client.php new file mode 100644 index 0000000..20b0c07 --- /dev/null +++ b/Elastic/Elasticsearch/Client.php @@ -0,0 +1,175 @@ +transport = $transport; + $this->logger = $logger; + + $this->defaultTransportSettings($this->transport); + } + + /** + * @inheritdoc + */ + public function getTransport(): Transport + { + return $this->transport; + } + + /** + * @inheritdoc + */ + public function getLogger(): LoggerInterface + { + return $this->logger; + } + + /** + * Set the default settings for Elasticsearch + */ + protected function defaultTransportSettings(Transport $transport): void + { + $transport->setUserAgent('elasticsearch-php', self::VERSION); + } + + /** + * @inheritdoc + */ + public function setAsync(bool $async): self + { + $this->async = $async; + return $this; + } + + /** + * @inheritdoc + */ + public function getAsync(): bool + { + return $this->async; + } + + /** + * @inheritdoc + */ + public function setElasticMetaHeader(bool $active): self + { + $this->elasticMetaHeader = $active; + return $this; + } + + /** + * @inheritdoc + */ + public function getElasticMetaHeader(): bool + { + return $this->elasticMetaHeader; + } + + /** + * @inheritdoc + */ + public function setResponseException(bool $active): self + { + $this->responseException = $active; + return $this; + } + + /** + * @inheritdoc + */ + public function getResponseException(): bool + { + return $this->responseException; + } + + /** + * @inheritdoc + */ + public function sendRequest(RequestInterface $request) + { + // If async returns a Promise + if ($this->getAsync()) { + if ($this->getElasticMetaHeader()) { + $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, true); + } + $this->transport->setAsyncOnSuccess( + $request->getMethod() === 'HEAD' + ? new AsyncOnSuccessNoException + : ($this->getResponseException() ? new AsyncOnSuccess : new AsyncOnSuccessNoException) + ); + return $this->transport->sendAsyncRequest($request); + } + + if ($this->getElasticMetaHeader()) { + $this->transport->setElasticMetaHeader(Client::CLIENT_NAME, Client::VERSION, false); + } + $start = microtime(true); + $response = $this->transport->sendRequest($request); + $this->logger->info(sprintf("Response time in %.3f sec", microtime(true) - $start)); + + $result = new Elasticsearch; + $result->setResponse($response, $request->getMethod() === 'HEAD' ? false : $this->getResponseException()); + return $result; + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/ClientBuilder.php b/Elastic/Elasticsearch/ClientBuilder.php new file mode 100644 index 0000000..41ae53e --- /dev/null +++ b/Elastic/Elasticsearch/ClientBuilder.php @@ -0,0 +1,467 @@ + $value) { + $method = "set$key"; + $reflection = new ReflectionClass($builder); + if ($reflection->hasMethod($method)) { + $func = $reflection->getMethod($method); + if ($func->getNumberOfParameters() > 1) { + $builder->$method(...$value); + } else { + $builder->$method($value); + } + unset($config[$key]); + } + } + + if ($quiet === false && count($config) > 0) { + $unknown = implode(array_keys($config)); + throw new ConfigException("Unknown parameters provided: $unknown"); + } + return $builder->build(); + } + + public function setHttpClient(ClientInterface $httpClient): ClientBuilder + { + $this->httpClient = $httpClient; + return $this; + } + + public function setAsyncHttpClient(HttpAsyncClient $asyncHttpClient): ClientBuilder + { + $this->asyncHttpClient = $asyncHttpClient; + return $this; + } + + /** + * Set the PSR-3 Logger + */ + public function setLogger(LoggerInterface $logger): ClientBuilder + { + $this->logger = $logger; + return $this; + } + + /** + * Set the NodePool + */ + public function setNodePool(NodePoolInterface $nodePool): ClientBuilder + { + $this->nodePool = $nodePool; + return $this; + } + + /** + * Set the hosts (nodes) + */ + public function setHosts(array $hosts): ClientBuilder + { + $this->hosts = $hosts; + return $this; + } + + /** + * Set the ApiKey + * If the id is not specified we store the ApiKey otherwise + * we store as Base64(id:ApiKey) + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html + */ + public function setApiKey(string $apiKey, string $id = null): ClientBuilder + { + if (empty($id)) { + $this->apiKey = $apiKey; + } else { + $this->apiKey = base64_encode($id . ':' . $apiKey); + } + return $this; + } + + /** + * Set the Basic Authentication + */ + public function setBasicAuthentication(string $username, string $password): ClientBuilder + { + $this->username = $username; + $this->password = $password; + return $this; + } + + public function setElasticCloudId(string $cloudId) + { + $this->cloudId = $cloudId; + return $this; + } + + /** + * Set number or retries + * + * @param int $retries + */ + public function setRetries(int $retries): ClientBuilder + { + if ($retries < 0) { + throw new InvalidArgumentException('The retries number must be >= 0'); + } + $this->retries = $retries; + return $this; + } + + /** + * Set SSL certificate + * + * @param string $cert The name of a file containing a PEM formatted certificate + * @param string $password if the certificate requires a password + */ + public function setSSLCert(string $cert, string $password = null): ClientBuilder + { + $this->sslCert = [$cert, $password]; + return $this; + } + + /** + * Set the Certificate Authority (CA) bundle + * + * @param string $cert The name of a file containing a PEM formatted certificate + */ + public function setCABundle(string $cert): ClientBuilder + { + $this->sslCA = $cert; + return $this; + } + + /** + * Set SSL key + * + * @param string $key The name of a file containing a private SSL key + * @param string $password if the private key requires a password + */ + public function setSSLKey(string $key, string $password = null): ClientBuilder + { + $this->sslKey = [$key, $password]; + return $this; + } + + /** + * Enable or disable the SSL verification + */ + public function setSSLVerification(bool $value = true): ClientBuilder + { + $this->sslVerification = $value; + return $this; + } + + /** + * Enable or disable the x-elastic-client-meta header + */ + public function setElasticMetaHeader(bool $value = true): ClientBuilder + { + $this->elasticMetaHeader = $value; + return $this; + } + + public function setHttpClientOptions(array $options): ClientBuilder + { + $this->httpClientOptions = $options; + return $this; + } + + /** + * Build and returns the Client object + */ + public function build(): Client + { + // Transport builder + $builder = TransportBuilder::create(); + + // Set the default hosts if empty + if (empty($this->hosts)) { + $this->hosts = [self::DEFAULT_HOST]; + } + $builder->setHosts($this->hosts); + + // Logger + if (!empty($this->logger)) { + $builder->setLogger($this->logger); + } + + // Http client + if (!empty($this->httpClient)) { + $builder->setClient($this->httpClient); + } + // Set HTTP client options + $builder->setClient( + $this->setOptions($builder->getClient(), $this->getConfig(), $this->httpClientOptions) + ); + + // Cloud id + if (!empty($this->cloudId)) { + $builder->setCloudId($this->cloudId); + } + + // Node Pool + if (!empty($this->nodePool)) { + $builder->setNodePool($this->nodePool); + } + + $transport = $builder->build(); + + // The default retries is equal to the number of hosts + if (empty($this->retries)) { + $this->retries = count($this->hosts); + } + $transport->setRetries($this->retries); + + // Async client + if (!empty($this->asyncHttpClient)) { + $transport->setAsyncClient($this->asyncHttpClient); + } + + // Basic authentication + if (!empty($this->username) && !empty($this->password)) { + $transport->setUserInfo($this->username, $this->password); + } + + // API key + if (!empty($this->apiKey)) { + if (!empty($this->username)) { + throw new AuthenticationException('You cannot use APIKey and Basic Authenication together'); + } + $transport->setHeader('Authorization', sprintf("ApiKey %s", $this->apiKey)); + } + + /** + * Elastic cloud optimized with gzip + * @see https://github.com/elastic/elasticsearch-php/issues/1241 omit for Symfony HTTP Client + */ + if (!empty($this->cloudId) && !$this->isSymfonyHttpClient($transport)) { + $transport->setHeader('Accept-Encoding', 'gzip'); + } + + $client = new Client($transport, $transport->getLogger()); + // Enable or disable the x-elastic-client-meta header + $client->setElasticMetaHeader($this->elasticMetaHeader); + + return $client; + } + + /** + * Returns true if the transport HTTP client is Symfony + */ + protected function isSymfonyHttpClient(Transport $transport): bool + { + if (false !== strpos(get_class($transport->getClient()), 'Symfony\Component\HttpClient')) { + return true; + } + if (false !== strpos(get_class($transport->getAsyncClient()), 'Symfony\Component\HttpClient')) { + return true; + } + return false; + } + + /** + * Returns the configuration to be used in the HTTP client + */ + protected function getConfig(): array + { + $config = []; + if (!empty($this->sslCert)) { + $config[RequestOptions::SSL_CERT] = $this->sslCert; + } + if (!empty($this->sslKey)) { + $config[RequestOptions::SSL_KEY] = $this->sslKey; + } + if (!$this->sslVerification) { + $config[RequestOptions::SSL_VERIFY] = false; + } + if (!empty($this->sslCA)) { + $config[RequestOptions::SSL_CA] = $this->sslCA; + } + return $config; + } + + /** + * Set the configuration for the specific HTTP client using an adapter + */ + protected function setOptions(ClientInterface $client, array $config, array $clientOptions = []): ClientInterface + { + if (empty($config) && empty($clientOptions)) { + return $client; + } + $class = get_class($client); + if (!isset(AdapterOptions::HTTP_ADAPTERS[$class])) { + throw new HttpClientException(sprintf( + "The HTTP client %s is not supported for custom options", + $class + )); + } + $adapterClass = AdapterOptions::HTTP_ADAPTERS[$class]; + if (!class_exists($adapterClass) || !in_array(AdapterInterface::class, class_implements($adapterClass))) { + throw new HttpClientException(sprintf( + "The class %s does not exists or does not implement %s", + $adapterClass, + AdapterInterface::class + )); + } + $adapter = new $adapterClass; + return $adapter->setConfig($client, $config, $clientOptions); + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/ClientInterface.php b/Elastic/Elasticsearch/ClientInterface.php new file mode 100644 index 0000000..04b982c --- /dev/null +++ b/Elastic/Elasticsearch/ClientInterface.php @@ -0,0 +1,72 @@ +client = $client; + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Endpoints/AsyncSearch.php b/Elastic/Elasticsearch/Endpoints/AsyncSearch.php new file mode 100644 index 0000000..b11a520 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/AsyncSearch.php @@ -0,0 +1,217 @@ +checkRequiredParameters(['id'], $params); + $url = '/_async_search/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves the results of a previously submitted async search request given its ID. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html + * + * @param array{ + * id: string, // (REQUIRED) The async search ID + * wait_for_completion_timeout: time, // Specify the time that the request should block waiting for the final response + * keep_alive: time, // Specify the time interval in which the results (partial or final) for this search will be available + * typed_keys: boolean, // Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * 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 get(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_async_search/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['wait_for_completion_timeout','keep_alive','typed_keys','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves the status of a previously submitted async search request given its ID. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html + * + * @param array{ + * id: string, // (REQUIRED) The async search ID + * 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 status(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_async_search/status/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Executes a search request asynchronously. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html + * + * @param array{ + * index: list, // A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * wait_for_completion_timeout: time, // Specify the time that the request should block waiting for the final response + * keep_on_completion: boolean, // Control whether the response should be stored in the cluster if it completed within the provided [wait_for_completion] time (default: false) + * keep_alive: time, // Update the time interval in which the results (partial or final) for this search will be available + * batched_reduce_size: number, // The number of shard results that should be reduced at once on the coordinating node. This value should be used as the granularity at which progress results will be made available. + * request_cache: boolean, // Specify if request cache should be used for this request or not, defaults to true + * analyzer: string, // The analyzer to use for the query string + * analyze_wildcard: boolean, // Specify whether wildcard and prefix queries should be analyzed (default: false) + * default_operator: enum, // The default operator for query string query (AND or OR) + * df: string, // The field to use as default where no field prefix is given in the query string + * explain: boolean, // Specify whether to return detailed information about score computation as part of a hit + * stored_fields: list, // A comma-separated list of stored fields to return as part of a hit + * docvalue_fields: list, // A comma-separated list of fields to return as the docvalue representation of a field for each hit + * from: number, // Starting offset (default: 0) + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * ignore_throttled: boolean, // Whether specified concrete, expanded or aliased indices should be ignored when throttled + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * lenient: boolean, // Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * q: string, // Query in the Lucene query string syntax + * routing: list, // A comma-separated list of specific routing values + * search_type: enum, // Search operation type + * size: number, // Number of hits to return (default: 10) + * sort: list, // A comma-separated list of : pairs + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * terminate_after: number, // The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * stats: list, // Specific 'tag' of the request for logging and statistical purposes + * suggest_field: string, // Specify which field to use for suggestions + * suggest_mode: enum, // Specify suggest mode + * suggest_size: number, // How many suggestions to return in response + * suggest_text: string, // The source text for which the suggestions should be returned + * timeout: time, // Explicit operation timeout + * track_scores: boolean, // Whether to calculate and return scores even if they are not used for sorting + * track_total_hits: boolean|long, // Indicate if the number of documents that match the query should be tracked. A number can also be specified, to accurately track the total hit count up to the number. + * allow_partial_search_results: boolean, // Indicate if an error should be returned if there is a partial search failure or timeout + * typed_keys: boolean, // Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * version: boolean, // Specify whether to return document version as part of a hit + * seq_no_primary_term: boolean, // Specify whether to return sequence number and primary term of the last modification of each hit + * max_concurrent_shard_requests: number, // The number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests + * 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, // The search definition using the Query DSL + * } $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 submit(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_async_search'; + $method = 'POST'; + } else { + $url = '/_async_search'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['wait_for_completion_timeout','keep_on_completion','keep_alive','batched_reduce_size','request_cache','analyzer','analyze_wildcard','default_operator','df','explain','stored_fields','docvalue_fields','from','ignore_unavailable','ignore_throttled','allow_no_indices','expand_wildcards','lenient','preference','q','routing','search_type','size','sort','_source','_source_excludes','_source_includes','terminate_after','stats','suggest_field','suggest_mode','suggest_size','suggest_text','timeout','track_scores','track_total_hits','allow_partial_search_results','typed_keys','version','seq_no_primary_term','max_concurrent_shard_requests','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Autoscaling.php b/Elastic/Elasticsearch/Endpoints/Autoscaling.php new file mode 100644 index 0000000..9ea7a98 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Autoscaling.php @@ -0,0 +1,168 @@ +checkRequiredParameters(['name'], $params); + $url = '/_autoscaling/policy/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets the current autoscaling capacity based on the configured autoscaling policy. Designed for indirect use by ECE/ESS and ECK. Direct use is not supported. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-get-autoscaling-capacity.html + * + * @param array{ + * 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 getAutoscalingCapacity(array $params = []) + { + $url = '/_autoscaling/capacity'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves an autoscaling policy. Designed for indirect use by ECE/ESS and ECK. Direct use is not supported. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-get-autoscaling-policy.html + * + * @param array{ + * name: string, // (REQUIRED) the name of the autoscaling policy + * 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 getAutoscalingPolicy(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_autoscaling/policy/' . $this->encode($params['name']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a new autoscaling policy. Designed for indirect use by ECE/ESS and ECK. Direct use is not supported. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-put-autoscaling-policy.html + * + * @param array{ + * name: string, // (REQUIRED) the name of the autoscaling policy + * 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 specification of the autoscaling policy + * } $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 putAutoscalingPolicy(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_autoscaling/policy/' . $this->encode($params['name']); + $method = 'PUT'; + + $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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Cat.php b/Elastic/Elasticsearch/Endpoints/Cat.php new file mode 100644 index 0000000..a33023c --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Cat.php @@ -0,0 +1,1147 @@ +encode($params['name']); + $method = 'GET'; + } else { + $url = '/_cat/aliases'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','local','h','help','s','v','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Provides a snapshot of how many shards are allocated to each data node and how much disk space they are using. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html + * + * @param array{ + * node_id: list, // A comma-separated list of node IDs or names to limit the returned information + * format: string, // a short version of the Accept header, e.g. json, yaml + * bytes: enum, // The unit in which to display byte values + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 allocation(array $params = []) + { + if (isset($params['node_id'])) { + $url = '/_cat/allocation/' . $this->encode($params['node_id']); + $method = 'GET'; + } else { + $url = '/_cat/allocation'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','bytes','local','master_timeout','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about existing component_templates templates. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-compoentn-templates.html + * + * @param array{ + * name: string, // A pattern that returned component template names must match + * format: string, // a short version of the Accept header, e.g. json, yaml + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 componentTemplates(array $params = []) + { + if (isset($params['name'])) { + $url = '/_cat/component_templates/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_cat/component_templates'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','local','master_timeout','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Provides quick access to the document count of the entire cluster, or individual indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html + * + * @param array{ + * index: list, // A comma-separated list of index names to limit the returned information + * format: string, // a short version of the Accept header, e.g. json, yaml + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 count(array $params = []) + { + if (isset($params['index'])) { + $url = '/_cat/count/' . $this->encode($params['index']); + $method = 'GET'; + } else { + $url = '/_cat/count'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Shows how much heap memory is currently being used by fielddata on every data node in the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html + * + * @param array{ + * fields: list, // A comma-separated list of fields to return the fielddata size + * format: string, // a short version of the Accept header, e.g. json, yaml + * bytes: enum, // The unit in which to display byte values + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 fielddata(array $params = []) + { + if (isset($params['fields'])) { + $url = '/_cat/fielddata/' . $this->encode($params['fields']); + $method = 'GET'; + } else { + $url = '/_cat/fielddata'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','bytes','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a concise representation of the cluster health. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * ts: boolean, // Set to false to disable timestamping + * v: boolean, // Verbose mode. Display column headers + * 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 health(array $params = []) + { + $url = '/_cat/health'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['format','h','help','s','time','ts','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns help for the Cat APIs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html + * + * @param array{ + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * 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 help(array $params = []) + { + $url = '/_cat'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['help','s','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about indices: number of primaries and replicas, document counts, disk size, ... + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html + * + * @param array{ + * index: list, // A comma-separated list of index names to limit the returned information + * format: string, // a short version of the Accept header, e.g. json, yaml + * bytes: enum, // The unit in which to display byte values + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * health: enum, // A health status ("green", "yellow", or "red" to filter only indices matching the specified health status + * help: boolean, // Return help information + * pri: boolean, // Set to true to return stats only for primary shards + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * include_unloaded_segments: boolean, // If set to true segment stats will include stats for segments that are not currently loaded into memory + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 indices(array $params = []) + { + if (isset($params['index'])) { + $url = '/_cat/indices/' . $this->encode($params['index']); + $method = 'GET'; + } else { + $url = '/_cat/indices'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','bytes','master_timeout','h','health','help','pri','s','time','v','include_unloaded_segments','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about the master node. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 master(array $params = []) + { + $url = '/_cat/master'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['format','local','master_timeout','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets configuration and usage information about data frame analytics jobs. + * + * @see http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-dfanalytics.html + * + * @param array{ + * id: string, // The ID of the data frame analytics to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no configs. (This includes `_all` string or when no configs have been specified) + * bytes: enum, // The unit in which to display byte values + * format: string, // a short version of the Accept header, e.g. json, yaml + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 mlDataFrameAnalytics(array $params = []) + { + if (isset($params['id'])) { + $url = '/_cat/ml/data_frame/analytics/' . $this->encode($params['id']); + $method = 'GET'; + } else { + $url = '/_cat/ml/data_frame/analytics'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','bytes','format','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets configuration and usage information about datafeeds. + * + * @see http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-datafeeds.html + * + * @param array{ + * datafeed_id: string, // The ID of the datafeeds stats to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + * format: string, // a short version of the Accept header, e.g. json, yaml + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 mlDatafeeds(array $params = []) + { + if (isset($params['datafeed_id'])) { + $url = '/_cat/ml/datafeeds/' . $this->encode($params['datafeed_id']); + $method = 'GET'; + } else { + $url = '/_cat/ml/datafeeds'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','format','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets configuration and usage information about anomaly detection jobs. + * + * @see http://www.elastic.co/guide/en/elasticsearch/reference/current/cat-anomaly-detectors.html + * + * @param array{ + * job_id: string, // The ID of the jobs stats to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + * bytes: enum, // The unit in which to display byte values + * format: string, // a short version of the Accept header, e.g. json, yaml + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 mlJobs(array $params = []) + { + if (isset($params['job_id'])) { + $url = '/_cat/ml/anomaly_detectors/' . $this->encode($params['job_id']); + $method = 'GET'; + } else { + $url = '/_cat/ml/anomaly_detectors'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','bytes','format','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets configuration and usage information about inference trained models. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-trained-model.html + * + * @param array{ + * model_id: string, // The ID of the trained models stats to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no trained models. (This includes `_all` string or when no trained models have been specified) + * from: int, // skips a number of trained models + * size: int, // specifies a max number of trained models to get + * bytes: enum, // The unit in which to display byte values + * format: string, // a short version of the Accept header, e.g. json, yaml + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 mlTrainedModels(array $params = []) + { + if (isset($params['model_id'])) { + $url = '/_cat/ml/trained_models/' . $this->encode($params['model_id']); + $method = 'GET'; + } else { + $url = '/_cat/ml/trained_models'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','from','size','bytes','format','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about custom node attributes. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 nodeattrs(array $params = []) + { + $url = '/_cat/nodeattrs'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['format','local','master_timeout','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns basic statistics about performance of cluster nodes. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html + * + * @param array{ + * bytes: enum, // The unit in which to display byte values + * format: string, // a short version of the Accept header, e.g. json, yaml + * full_id: boolean, // Return the full node ID instead of the shortened version (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * include_unloaded_segments: boolean, // If set to true segment stats will include stats for segments that are not currently loaded into memory + * 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 nodes(array $params = []) + { + $url = '/_cat/nodes'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['bytes','format','full_id','master_timeout','h','help','s','time','v','include_unloaded_segments','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a concise representation of the cluster pending tasks. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 pendingTasks(array $params = []) + { + $url = '/_cat/pending_tasks'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['format','local','master_timeout','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about installed plugins across nodes node. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * include_bootstrap: boolean, // Include bootstrap plugins in the response + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 plugins(array $params = []) + { + $url = '/_cat/plugins'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['format','local','master_timeout','h','help','include_bootstrap','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about index shard recoveries, both on-going completed. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html + * + * @param array{ + * index: list, // Comma-separated list or wildcard expression of index names to limit the returned information + * format: string, // a short version of the Accept header, e.g. json, yaml + * active_only: boolean, // If `true`, the response only includes ongoing shard recoveries + * bytes: enum, // The unit in which to display byte values + * detailed: boolean, // If `true`, the response includes detailed information about shard recoveries + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 recovery(array $params = []) + { + if (isset($params['index'])) { + $url = '/_cat/recovery/' . $this->encode($params['index']); + $method = 'GET'; + } else { + $url = '/_cat/recovery'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','active_only','bytes','detailed','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about snapshot repositories registered in the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * local: boolean, // Return local information, do not retrieve the state from master node + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 repositories(array $params = []) + { + $url = '/_cat/repositories'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['format','local','master_timeout','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Provides low-level information about the segments in the shards of an index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html + * + * @param array{ + * index: list, // A comma-separated list of index names to limit the returned information + * format: string, // a short version of the Accept header, e.g. json, yaml + * bytes: enum, // The unit in which to display byte values + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 segments(array $params = []) + { + if (isset($params['index'])) { + $url = '/_cat/segments/' . $this->encode($params['index']); + $method = 'GET'; + } else { + $url = '/_cat/segments'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','bytes','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Provides a detailed view of shard allocation on nodes. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html + * + * @param array{ + * index: list, // A comma-separated list of index names to limit the returned information + * format: string, // a short version of the Accept header, e.g. json, yaml + * bytes: enum, // The unit in which to display byte values + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 shards(array $params = []) + { + if (isset($params['index'])) { + $url = '/_cat/shards/' . $this->encode($params['index']); + $method = 'GET'; + } else { + $url = '/_cat/shards'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','bytes','master_timeout','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns all snapshots in a specific repository. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html + * + * @param array{ + * repository: list, // Name of repository from which to fetch the snapshot information + * format: string, // a short version of the Accept header, e.g. json, yaml + * ignore_unavailable: boolean, // Set to true to ignore unavailable snapshots + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 snapshots(array $params = []) + { + if (isset($params['repository'])) { + $url = '/_cat/snapshots/' . $this->encode($params['repository']); + $method = 'GET'; + } else { + $url = '/_cat/snapshots'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','ignore_unavailable','master_timeout','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about the tasks currently executing on one or more nodes in the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * nodes: list, // A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * actions: list, // A comma-separated list of actions that should be returned. Leave empty to return all. + * detailed: boolean, // Return detailed task information (default: false) + * parent_task_id: string, // Return tasks with specified parent task id (node_id:task_number). Set to -1 to return all. + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 tasks(array $params = []) + { + $url = '/_cat/tasks'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['format','nodes','actions','detailed','parent_task_id','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about existing templates. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-templates.html + * + * @param array{ + * name: string, // A pattern that returned template names must match + * format: string, // a short version of the Accept header, e.g. json, yaml + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 templates(array $params = []) + { + if (isset($params['name'])) { + $url = '/_cat/templates/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_cat/templates'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','local','master_timeout','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns cluster-wide thread pool statistics per node. + * By default the active, queue and rejected statistics are returned for all thread pools. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html + * + * @param array{ + * thread_pool_patterns: list, // A comma-separated list of regular-expressions to filter the thread pools in the output + * format: string, // a short version of the Accept header, e.g. json, yaml + * time: enum, // The unit in which to display time values + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * v: boolean, // Verbose mode. Display column headers + * 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 threadPool(array $params = []) + { + if (isset($params['thread_pool_patterns'])) { + $url = '/_cat/thread_pool/' . $this->encode($params['thread_pool_patterns']); + $method = 'GET'; + } else { + $url = '/_cat/thread_pool'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['format','time','local','master_timeout','h','help','s','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets configuration and usage information about transforms. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-transforms.html + * + * @param array{ + * transform_id: string, // The id of the transform for which to get stats. '_all' or '*' implies all transforms + * from: int, // skips a number of transform configs, defaults to 0 + * size: int, // specifies a max number of transforms to get, defaults to 100 + * 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) + * format: string, // a short version of the Accept header, e.g. json, yaml + * h: list, // Comma-separated list of column names to display + * help: boolean, // Return help information + * s: list, // Comma-separated list of column names or column aliases to sort by + * time: enum, // The unit in which to display time values + * v: boolean, // Verbose mode. Display column headers + * 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 transforms(array $params = []) + { + if (isset($params['transform_id'])) { + $url = '/_cat/transforms/' . $this->encode($params['transform_id']); + $method = 'GET'; + } else { + $url = '/_cat/transforms'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['from','size','allow_no_match','format','h','help','s','time','v','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain,application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Ccr.php b/Elastic/Elasticsearch/Endpoints/Ccr.php new file mode 100644 index 0000000..454df7b --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Ccr.php @@ -0,0 +1,492 @@ +checkRequiredParameters(['name'], $params); + $url = '/_ccr/auto_follow/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a new follower index configured to follow the referenced leader index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the follower index + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before returning. Defaults to 0. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * 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 name of the leader index and other optional ccr related parameters + * } $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 follow(array $params = []) + { + $this->checkRequiredParameters(['index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_ccr/follow'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['wait_for_active_shards','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)); + } + + + /** + * Retrieves information about all follower indices, including parameters and status for each follower index + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index patterns; use `_all` to perform the operation on all indices + * 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 followInfo(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ccr/info'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves follower stats. return shard-level stats about the following tasks associated with each shard for the specified indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index patterns; use `_all` to perform the operation on all indices + * 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 followStats(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ccr/stats'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Removes the follower retention leases from the leader. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-forget-follower.html + * + * @param array{ + * index: string, // (REQUIRED) the name of the leader index for which specified follower retention leases should be removed + * 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 name and UUID of the follower index, the name of the cluster containing the follower index, and the alias from the perspective of that cluster for the remote cluster containing the leader index + * } $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 forgetFollower(array $params = []) + { + $this->checkRequiredParameters(['index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_ccr/forget_follower'; + $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)); + } + + + /** + * Gets configured auto-follow patterns. Returns the specified auto-follow pattern collection. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html + * + * @param array{ + * name: string, // The name of the auto follow pattern. + * 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 getAutoFollowPattern(array $params = []) + { + if (isset($params['name'])) { + $url = '/_ccr/auto_follow/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_ccr/auto_follow'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Pauses an auto-follow pattern + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-auto-follow-pattern.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the auto follow pattern that should pause discovering new indices to follow. + * 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 pauseAutoFollowPattern(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_ccr/auto_follow/' . $this->encode($params['name']) . '/pause'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Pauses a follower index. The follower index will not fetch any additional operations from the leader index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-pause-follow.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the follower index that should pause following its leader index. + * 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 pauseFollow(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ccr/pause_follow'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a new named collection of auto-follow patterns against a specified remote cluster. Newly created indices on the remote cluster matching any of the specified patterns will be automatically configured as follower indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-auto-follow-pattern.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the auto follow pattern. + * 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 specification of the auto follow pattern + * } $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 putAutoFollowPattern(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_ccr/auto_follow/' . $this->encode($params['name']); + $method = 'PUT'; + + $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)); + } + + + /** + * Resumes an auto-follow pattern that has been paused + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-auto-follow-pattern.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the auto follow pattern to resume discovering new indices to follow. + * 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 resumeAutoFollowPattern(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_ccr/auto_follow/' . $this->encode($params['name']) . '/resume'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Resumes a follower index that has been paused + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-resume-follow.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the follow index to resume following. + * 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, // The name of the leader index and other optional ccr related parameters + * } $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 resumeFollow(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ccr/resume_follow'; + $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)); + } + + + /** + * Gets all stats related to cross-cluster replication. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.html + * + * @param array{ + * 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 stats(array $params = []) + { + $url = '/_ccr/stats'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Stops the following task associated with a follower index and removes index metadata and settings associated with cross-cluster replication. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-unfollow.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the follower index that should be turned into a regular index. + * 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 unfollow(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ccr/unfollow'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Cluster.php b/Elastic/Elasticsearch/Endpoints/Cluster.php new file mode 100644 index 0000000..9832655 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Cluster.php @@ -0,0 +1,605 @@ +addQueryString($url, $params, ['include_yes_decisions','include_disk_info','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)); + } + + + /** + * Deletes a component template + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-component-template.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 deleteComponentTemplate(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_component_template/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Clears cluster voting config exclusions. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html + * + * @param array{ + * wait_for_removal: boolean, // Specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list. + * master_timeout: time, // Timeout for submitting request to master + * 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 deleteVotingConfigExclusions(array $params = []) + { + $url = '/_cluster/voting_config_exclusions'; + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['wait_for_removal','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about whether a particular component template exist + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-component-template.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * master_timeout: time, // Explicit operation timeout for connection to master node + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 existsComponentTemplate(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_component_template/' . $this->encode($params['name']); + $method = 'HEAD'; + + $url = $this->addQueryString($url, $params, ['master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns one or more component templates + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-component-template.html + * + * @param array{ + * name: list, // The comma separated names of the component templates + * master_timeout: time, // Explicit operation timeout for connection to master node + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 getComponentTemplate(array $params = []) + { + if (isset($params['name'])) { + $url = '/_component_template/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_component_template'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns cluster settings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-get-settings.html + * + * @param array{ + * flat_settings: boolean, // Return settings in flat format (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * include_defaults: boolean, // Whether to return all default clusters setting. + * 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 getSettings(array $params = []) + { + $url = '/_cluster/settings'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['flat_settings','master_timeout','timeout','include_defaults','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns basic information about the health of the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html + * + * @param array{ + * index: list, // Limit the information returned to a specific index + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * level: enum, // Specify the level of detail for returned information + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * wait_for_active_shards: string, // Wait until the specified number of shards is active + * wait_for_nodes: string, // Wait until the specified number of nodes is available + * wait_for_events: enum, // Wait until all currently queued events with the given priority are processed + * wait_for_no_relocating_shards: boolean, // Whether to wait until there are no relocating shards in the cluster + * wait_for_no_initializing_shards: boolean, // Whether to wait until there are no initializing shards in the cluster + * wait_for_status: enum, // Wait until cluster is in a specific state + * 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 health(array $params = []) + { + if (isset($params['index'])) { + $url = '/_cluster/health/' . $this->encode($params['index']); + $method = 'GET'; + } else { + $url = '/_cluster/health'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['expand_wildcards','level','local','master_timeout','timeout','wait_for_active_shards','wait_for_nodes','wait_for_events','wait_for_no_relocating_shards','wait_for_no_initializing_shards','wait_for_status','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a list of any cluster-level changes (e.g. create index, update mapping, + * allocate or fail shard) which have not yet been executed. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-pending.html + * + * @param array{ + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Specify timeout for connection to master + * 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 pendingTasks(array $params = []) + { + $url = '/_cluster/pending_tasks'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['local','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Updates the cluster voting config exclusions by node ids or node names. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html + * + * @param array{ + * node_ids: string, // A comma-separated list of the persistent ids of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_names. + * node_names: string, // A comma-separated list of the names of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_ids. + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Timeout for submitting request to master + * 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 postVotingConfigExclusions(array $params = []) + { + $url = '/_cluster/voting_config_exclusions'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['node_ids','node_names','timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates or updates a component template + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-component-template.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * create: boolean, // Whether the index template should only be added if new or can also replace an existing one + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 template definition + * } $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 putComponentTemplate(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_component_template/' . $this->encode($params['name']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['create','timeout','master_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)); + } + + + /** + * Updates the cluster settings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html + * + * @param array{ + * flat_settings: boolean, // Return settings in flat format (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * 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 settings to be updated. Can be either `transient` or `persistent` (survives cluster restart). + * } $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 putSettings(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_cluster/settings'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['flat_settings','master_timeout','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)); + } + + + /** + * Returns the information about configured remote clusters. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-remote-info.html + * + * @param array{ + * 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 remoteInfo(array $params = []) + { + $url = '/_remote/info'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to manually change the allocation of individual shards in the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-reroute.html + * + * @param array{ + * dry_run: boolean, // Simulate the operation only and return the resulting state + * explain: boolean, // Return an explanation of why the commands can or cannot be executed + * retry_failed: boolean, // Retries allocation of shards that are blocked due to too many subsequent allocation failures + * metric: list, // Limit the information returned to the specified metrics. Defaults to all but metadata + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * 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, // The definition of `commands` to perform (`move`, `cancel`, `allocate`) + * } $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 reroute(array $params = []) + { + $url = '/_cluster/reroute'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['dry_run','explain','retry_failed','metric','master_timeout','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)); + } + + + /** + * Returns a comprehensive information about the state of the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html + * + * @param array{ + * metric: list, // Limit the information returned to the specified metrics + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * master_timeout: time, // Specify timeout for connection to master + * flat_settings: boolean, // Return settings in flat format (default: false) + * wait_for_metadata_version: number, // Wait for the metadata version to be equal or greater than the specified metadata version + * wait_for_timeout: time, // The maximum time to wait for wait_for_metadata_version before timing out + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 state(array $params = []) + { + if (isset($params['index']) && isset($params['metric'])) { + $url = '/_cluster/state/' . $this->encode($params['metric']) . '/' . $this->encode($params['index']); + $method = 'GET'; + } elseif (isset($params['metric'])) { + $url = '/_cluster/state/' . $this->encode($params['metric']); + $method = 'GET'; + } else { + $url = '/_cluster/state'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['local','master_timeout','flat_settings','wait_for_metadata_version','wait_for_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns high-level overview of cluster statistics. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html + * + * @param array{ + * node_id: list, // A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * flat_settings: boolean, // Return settings in flat format (default: false) + * timeout: time, // Explicit operation timeout + * 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 stats(array $params = []) + { + if (isset($params['node_id'])) { + $url = '/_cluster/stats/nodes/' . $this->encode($params['node_id']); + $method = 'GET'; + } else { + $url = '/_cluster/stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['flat_settings','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/DanglingIndices.php b/Elastic/Elasticsearch/Endpoints/DanglingIndices.php new file mode 100644 index 0000000..96ddfc0 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/DanglingIndices.php @@ -0,0 +1,137 @@ +checkRequiredParameters(['index_uuid'], $params); + $url = '/_dangling/' . $this->encode($params['index_uuid']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['accept_data_loss','timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Imports the specified dangling index + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-gateway-dangling-indices.html + * + * @param array{ + * index_uuid: string, // (REQUIRED) The UUID of the dangling index + * accept_data_loss: boolean, // Must be set to true in order to import the dangling index + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 importDanglingIndex(array $params = []) + { + $this->checkRequiredParameters(['index_uuid'], $params); + $url = '/_dangling/' . $this->encode($params['index_uuid']); + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['accept_data_loss','timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns all dangling indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-gateway-dangling-indices.html + * + * @param array{ + * 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 listDanglingIndices(array $params = []) + { + $url = '/_dangling'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Enrich.php b/Elastic/Elasticsearch/Endpoints/Enrich.php new file mode 100644 index 0000000..597c5be --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Enrich.php @@ -0,0 +1,206 @@ +checkRequiredParameters(['name'], $params); + $url = '/_enrich/policy/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates the enrich index for an existing enrich policy. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/execute-enrich-policy-api.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the enrich policy + * wait_for_completion: boolean, // Should the request should block until the execution is complete. + * 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 executePolicy(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_enrich/policy/' . $this->encode($params['name']) . '/_execute'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['wait_for_completion','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets information about an enrich policy. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-enrich-policy-api.html + * + * @param array{ + * name: list, // A comma-separated list of enrich policy names + * 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 getPolicy(array $params = []) + { + if (isset($params['name'])) { + $url = '/_enrich/policy/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_enrich/policy'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a new enrich policy. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-enrich-policy-api.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the enrich policy + * 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 enrich policy to register + * } $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 putPolicy(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_enrich/policy/' . $this->encode($params['name']); + $method = 'PUT'; + + $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)); + } + + + /** + * Gets enrich coordinator statistics and information about enrich policies that are currently executing. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/enrich-stats-api.html + * + * @param array{ + * 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 stats(array $params = []) + { + $url = '/_enrich/_stats'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Eql.php b/Elastic/Elasticsearch/Endpoints/Eql.php new file mode 100644 index 0000000..d10e8a2 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Eql.php @@ -0,0 +1,176 @@ +checkRequiredParameters(['id'], $params); + $url = '/_eql/search/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns async results from previously executed Event Query Language (EQL) search + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + * + * @param array{ + * id: string, // (REQUIRED) The async search ID + * wait_for_completion_timeout: time, // Specify the time that the request should block waiting for the final response + * keep_alive: time, // Update the time interval in which the results (partial or final) for this search will be available + * 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 get(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_eql/search/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['wait_for_completion_timeout','keep_alive','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the status of a previously submitted async or stored Event Query Language (EQL) search + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + * + * @param array{ + * id: string, // (REQUIRED) The async search ID + * 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 getStatus(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_eql/search/status/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns results matching a query expressed in Event Query Language (EQL) + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the index to scope the operation + * wait_for_completion_timeout: time, // Specify the time that the request should block waiting for the final response + * keep_on_completion: boolean, // Control whether the response should be stored in the cluster if it completed within the provided [wait_for_completion] time (default: false) + * keep_alive: time, // Update the time interval in which the results (partial or final) for this search will be available + * 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) Eql request body. Use the `query` to limit the query scope. + * } $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 search(array $params = []) + { + $this->checkRequiredParameters(['index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_eql/search'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['wait_for_completion_timeout','keep_on_completion','keep_alive','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Features.php b/Elastic/Elasticsearch/Endpoints/Features.php new file mode 100644 index 0000000..cbd3af7 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Features.php @@ -0,0 +1,95 @@ +addQueryString($url, $params, ['master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Resets the internal state of features, usually by deleting system indices + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * 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 resetFeatures(array $params = []) + { + $url = '/_features/_reset'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Fleet.php b/Elastic/Elasticsearch/Endpoints/Fleet.php new file mode 100644 index 0000000..54da9c5 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Fleet.php @@ -0,0 +1,149 @@ +checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_fleet/global_checkpoints'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['wait_for_advance','wait_for_index','checkpoints','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)); + } + + + /** + * Multi Search API where the search will only be executed after specified checkpoints are available due to a refresh. This API is designed for internal use by the fleet server project. + * + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: string, // The index name to use as the default + * 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 request definitions (metadata-fleet search request definition pairs), separated by newlines + * } $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 msearch(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_fleet/_fleet_msearch'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_fleet/_fleet_msearch'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/x-ndjson', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Search API where the search will only be executed after specified checkpoints are available due to a refresh. This API is designed for internal use by the fleet server project. + * + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: string, // (REQUIRED) The index name to search. + * wait_for_checkpoints: list, // Comma separated list of checkpoints, one per shard + * wait_for_checkpoints_timeout: time, // Explicit wait_for_checkpoints timeout + * allow_partial_search_results: boolean, // Indicate if an error should be returned if there is a partial search failure or timeout + * 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, // The search definition using the Query DSL + * } $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 search(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_fleet/_fleet_search'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['wait_for_checkpoints','wait_for_checkpoints_timeout','allow_partial_search_results','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Graph.php b/Elastic/Elasticsearch/Endpoints/Graph.php new file mode 100644 index 0000000..0fd0e98 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Graph.php @@ -0,0 +1,68 @@ +checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_graph/explore'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['routing','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Ilm.php b/Elastic/Elasticsearch/Endpoints/Ilm.php new file mode 100644 index 0000000..f96674a --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Ilm.php @@ -0,0 +1,413 @@ +checkRequiredParameters(['policy'], $params); + $url = '/_ilm/policy/' . $this->encode($params['policy']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves information about the index's current lifecycle state, such as the currently executing phase, action, and step. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the index to explain + * only_managed: boolean, // filters the indices included in the response to ones managed by ILM + * only_errors: boolean, // filters the indices included in the response to ones in an ILM error state, implies only_managed + * 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 explainLifecycle(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ilm/explain'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['only_managed','only_errors','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the specified policy definition. Includes the policy version and last modified date. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-lifecycle.html + * + * @param array{ + * policy: string, // The name of the index lifecycle policy + * 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 getLifecycle(array $params = []) + { + if (isset($params['policy'])) { + $url = '/_ilm/policy/' . $this->encode($params['policy']); + $method = 'GET'; + } else { + $url = '/_ilm/policy'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves the current index lifecycle management (ILM) status. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-status.html + * + * @param array{ + * 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 getStatus(array $params = []) + { + $url = '/_ilm/status'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Migrates the indices and ILM policies away from custom node attribute allocation routing to data tiers routing + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-migrate-to-data-tiers.html + * + * @param array{ + * dry_run: boolean, // If set to true it will simulate the migration, providing a way to retrieve the ILM policies and indices that need to be migrated. The default is false + * 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, // Optionally specify a legacy index template name to delete and optionally specify a node attribute name used for index shard routing (defaults to "data") + * } $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 migrateToDataTiers(array $params = []) + { + $url = '/_ilm/migrate_to_data_tiers'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['dry_run','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)); + } + + + /** + * Manually moves an index into the specified step and executes that step. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the index whose lifecycle step is to change + * 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, // The new lifecycle step to move to + * } $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 moveToStep(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/_ilm/move/' . $this->encode($params['index']); + $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)); + } + + + /** + * Creates a lifecycle policy + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html + * + * @param array{ + * policy: string, // (REQUIRED) The name of the index lifecycle policy + * 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, // The lifecycle policy definition to register + * } $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 putLifecycle(array $params = []) + { + $this->checkRequiredParameters(['policy'], $params); + $url = '/_ilm/policy/' . $this->encode($params['policy']); + $method = 'PUT'; + + $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)); + } + + + /** + * Removes the assigned lifecycle policy and stops managing the specified index + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-remove-policy.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the index to remove policy on + * 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 removePolicy(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ilm/remove'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retries executing the policy for an index that is in the ERROR step. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the indices (comma-separated) whose failed lifecycle step is to be retry + * 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 retry(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_ilm/retry'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Start the index lifecycle management (ILM) plugin. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-start.html + * + * @param array{ + * 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 start(array $params = []) + { + $url = '/_ilm/start'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Halts all lifecycle management operations and stops the index lifecycle management (ILM) plugin + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-stop.html + * + * @param array{ + * 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 stop(array $params = []) + { + $url = '/_ilm/stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Indices.php b/Elastic/Elasticsearch/Endpoints/Indices.php new file mode 100644 index 0000000..e711f93 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Indices.php @@ -0,0 +1,2233 @@ +checkRequiredParameters(['index','block'], $params); + $url = '/' . $this->encode($params['index']) . '/_block/' . $this->encode($params['block']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Performs the analysis process on a text and return the tokens breakdown of the text. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html + * + * @param array{ + * index: string, // The name of the index to scope the operation + * 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, // Define analyzer/tokenizer parameters and the text on which the analysis should be performed + * } $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 analyze(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_analyze'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_analyze'; + $method = empty($params['body']) ? 'GET' : '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)); + } + + + /** + * Clears all or specific caches for one or more indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html + * + * @param array{ + * index: list, // A comma-separated list of index name to limit the operation + * fielddata: boolean, // Clear field data + * fields: list, // A comma-separated list of fields to clear when using the `fielddata` parameter (default: all) + * query: boolean, // Clear query caches + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * request: boolean, // Clear request cache + * 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 clearCache(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_cache/clear'; + $method = 'POST'; + } else { + $url = '/_cache/clear'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['fielddata','fields','query','ignore_unavailable','allow_no_indices','expand_wildcards','request','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Clones an index + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the source index to clone + * target: string, // (REQUIRED) The name of the target index to clone into + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * wait_for_active_shards: string, // Set the number of active shards to wait for on the cloned index before the operation 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. + * body: array, // The configuration for the target index (`settings` and `aliases`) + * } $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 clone(array $params = []) + { + $this->checkRequiredParameters(['index','target'], $params); + $url = '/' . $this->encode($params['index']) . '/_clone/' . $this->encode($params['target']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','wait_for_active_shards','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)); + } + + + /** + * Closes an index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html + * + * @param array{ + * index: list, // (REQUIRED) A comma separated list of indices to close + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * wait_for_active_shards: string, // Sets the number of active shards to wait for before the operation 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 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 close(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_close'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','wait_for_active_shards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates an index with optional settings and mappings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the index + * wait_for_active_shards: string, // Set the number of active shards to wait for before the operation returns. + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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, // The configuration for the index (`settings` and `mappings`) + * } $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 create(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['wait_for_active_shards','timeout','master_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)); + } + + + /** + * Creates a data stream + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the data stream + * 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 createDataStream(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_data_stream/' . $this->encode($params['name']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Provides statistics on operations happening in a data stream. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + * + * @param array{ + * name: list, // A comma-separated list of data stream names; use `_all` or empty string to perform the operation on all data streams + * 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 dataStreamsStats(array $params = []) + { + if (isset($params['name'])) { + $url = '/_data_stream/' . $this->encode($params['name']) . '/_stats'; + $method = 'GET'; + } else { + $url = '/_data_stream/_stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-delete-index.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of indices to delete; use `_all` or `*` string to delete all indices + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * ignore_unavailable: boolean, // Ignore unavailable indexes (default: false) + * allow_no_indices: boolean, // Ignore if a wildcard expression resolves to no concrete indices (default: false) + * expand_wildcards: enum, // Whether wildcard expressions should get expanded to open, closed, or hidden indices + * 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 delete(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an alias. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names (supports wildcards); use `_all` for all indices + * name: list, // (REQUIRED) A comma-separated list of aliases to delete (supports wildcards); use `_all` to delete all aliases for the specified indices. + * timeout: time, // Explicit timestamp for the document + * master_timeout: time, // Specify timeout for connection to master + * 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 deleteAlias(array $params = []) + { + $this->checkRequiredParameters(['index','name'], $params); + $url = '/' . $this->encode($params['index']) . '/_alias/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes a data stream. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + * + * @param array{ + * name: list, // (REQUIRED) A comma-separated list of data streams to delete; use `*` to delete all data streams + * expand_wildcards: enum, // Whether wildcard expressions should get expanded to open or closed indices (default: open) + * 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 deleteDataStream(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_data_stream/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an index template. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 deleteIndexTemplate(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_index_template/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an index template. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 deleteTemplate(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_template/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Analyzes the disk usage of each field of an index or data stream + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-disk-usage.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: string, // (REQUIRED) Comma-separated list of indices or data streams to analyze the disk usage + * run_expensive_tasks: boolean, // Must be set to [true] in order for the task to be performed. Defaults to false. + * flush: boolean, // Whether flush or not before analyzing the index disk usage. Defaults to true + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 diskUsage(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_disk_usage'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['run_expensive_tasks','flush','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Downsample an index + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/xpack-rollup.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: string, // (REQUIRED) The index to downsample + * target_index: string, // (REQUIRED) The name of the target index to store downsampled data + * 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 downsampling configuration + * } $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 downsample(array $params = []) + { + $this->checkRequiredParameters(['index','target_index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_downsample/' . $this->encode($params['target_index']); + $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)); + } + + + /** + * Returns information about whether a particular index exists. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * ignore_unavailable: boolean, // Ignore unavailable indexes (default: false) + * allow_no_indices: boolean, // Ignore if a wildcard expression resolves to no concrete indices (default: false) + * expand_wildcards: enum, // Whether wildcard expressions should get expanded to open or closed indices (default: open) + * flat_settings: boolean, // Return settings in flat format (default: false) + * include_defaults: boolean, // Whether to return all default setting for each of the indices. + * 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 exists(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']); + $method = 'HEAD'; + + $url = $this->addQueryString($url, $params, ['local','ignore_unavailable','allow_no_indices','expand_wildcards','flat_settings','include_defaults','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about whether a particular alias exists. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + * + * @param array{ + * name: list, // (REQUIRED) A comma-separated list of alias names to return + * index: list, // A comma-separated list of index names to filter aliases + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 existsAlias(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_alias/' . $this->encode($params['name']); + $method = 'HEAD'; + } else { + $url = '/_alias/' . $this->encode($params['name']); + $method = 'HEAD'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about whether a particular index template exists. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * flat_settings: boolean, // Return settings in flat format (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 existsIndexTemplate(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_index_template/' . $this->encode($params['name']); + $method = 'HEAD'; + + $url = $this->addQueryString($url, $params, ['flat_settings','master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about whether a particular index template exists. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: list, // (REQUIRED) The comma separated names of the index templates + * flat_settings: boolean, // Return settings in flat format (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 existsTemplate(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_template/' . $this->encode($params['name']); + $method = 'HEAD'; + + $url = $this->addQueryString($url, $params, ['flat_settings','master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the field usage stats for each field of an index + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/field-usage-stats.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: string, // (REQUIRED) A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * fields: list, // A comma-separated list of fields to include in the stats if only a subset of fields should be returned (supports wildcards) + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 fieldUsageStats(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_field_usage_stats'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['fields','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Performs the flush operation on one or more indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string for all indices + * force: boolean, // Whether a flush should be forced even if it is not necessarily needed ie. if no changes will be committed to the index. This is useful if transaction log IDs should be incremented even if no uncommitted changes are present. (This setting can be considered as internal) + * wait_if_ongoing: boolean, // If set to true the flush operation will block until the flush can be executed if another flush operation is already executing. The default is true. If set to false the flush will be skipped iff if another flush operation is already running. + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 flush(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_flush'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_flush'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['force','wait_if_ongoing','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Performs the force merge operation on one or more indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * flush: boolean, // Specify whether the index should be flushed after performing the operation (default: true) + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * max_num_segments: number, // The number of segments the index should be merged into (default: dynamic) + * only_expunge_deletes: boolean, // Specify whether the operation should only expunge deleted documents + * wait_for_completion: boolean, // Should the request wait until the force merge is completed. + * 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 forcemerge(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_forcemerge'; + $method = 'POST'; + } else { + $url = '/_forcemerge'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['flush','ignore_unavailable','allow_no_indices','expand_wildcards','max_num_segments','only_expunge_deletes','wait_for_completion','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about one or more indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * ignore_unavailable: boolean, // Ignore unavailable indexes (default: false) + * allow_no_indices: boolean, // Ignore if a wildcard expression resolves to no concrete indices (default: false) + * expand_wildcards: enum, // Whether wildcard expressions should get expanded to open or closed indices (default: open) + * features: enum, // Return only information on specified index features + * flat_settings: boolean, // Return settings in flat format (default: false) + * include_defaults: boolean, // Whether to return all default setting for each of the indices. + * master_timeout: time, // Specify timeout for connection to master + * 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 get(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['local','ignore_unavailable','allow_no_indices','expand_wildcards','features','flat_settings','include_defaults','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns an alias. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + * + * @param array{ + * name: list, // A comma-separated list of alias names to return + * index: list, // A comma-separated list of index names to filter aliases + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 getAlias(array $params = []) + { + if (isset($params['index']) && isset($params['name'])) { + $url = '/' . $this->encode($params['index']) . '/_alias/' . $this->encode($params['name']); + $method = 'GET'; + } elseif (isset($params['name'])) { + $url = '/_alias/' . $this->encode($params['name']); + $method = 'GET'; + } elseif (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_alias'; + $method = 'GET'; + } else { + $url = '/_alias'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns data streams. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + * + * @param array{ + * name: list, // A comma-separated list of data streams to get; use `*` to get all data streams + * expand_wildcards: enum, // Whether wildcard expressions should get expanded to open or closed indices (default: open) + * 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 getDataStream(array $params = []) + { + if (isset($params['name'])) { + $url = '/_data_stream/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_data_stream'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns mapping for one or more fields. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html + * + * @param array{ + * fields: list, // (REQUIRED) A comma-separated list of fields + * index: list, // A comma-separated list of index names + * include_defaults: boolean, // Whether the default mapping values should be returned as well + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 getFieldMapping(array $params = []) + { + $this->checkRequiredParameters(['fields'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_mapping/field/' . $this->encode($params['fields']); + $method = 'GET'; + } else { + $url = '/_mapping/field/' . $this->encode($params['fields']); + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['include_defaults','ignore_unavailable','allow_no_indices','expand_wildcards','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns an index template. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // A pattern that returned template names must match + * flat_settings: boolean, // Return settings in flat format (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 getIndexTemplate(array $params = []) + { + if (isset($params['name'])) { + $url = '/_index_template/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_index_template'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['flat_settings','master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns mappings for one or more indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html + * + * @param array{ + * index: list, // A comma-separated list of index names + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * master_timeout: time, // Specify timeout for connection to master + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 getMapping(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_mapping'; + $method = 'GET'; + } else { + $url = '/_mapping'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns settings for one or more indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * name: list, // The name of the settings that should be included + * master_timeout: time, // Specify timeout for connection to master + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * flat_settings: boolean, // Return settings in flat format (default: false) + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * include_defaults: boolean, // Whether to return all default setting for each of the indices. + * 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 getSettings(array $params = []) + { + if (isset($params['index']) && isset($params['name'])) { + $url = '/' . $this->encode($params['index']) . '/_settings/' . $this->encode($params['name']); + $method = 'GET'; + } elseif (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_settings'; + $method = 'GET'; + } elseif (isset($params['name'])) { + $url = '/_settings/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_settings'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['master_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','flat_settings','local','include_defaults','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns an index template. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: list, // The comma separated names of the index templates + * flat_settings: boolean, // Return settings in flat format (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 getTemplate(array $params = []) + { + if (isset($params['name'])) { + $url = '/_template/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_template'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['flat_settings','master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Migrates an alias to a data stream + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the alias to migrate + * 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 migrateToDataStream(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_data_stream/_migrate/' . $this->encode($params['name']); + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Modifies a data stream + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + * + * @param array{ + * 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 data stream modifications + * } $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 modifyDataStream(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_data_stream/_modify'; + $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)); + } + + + /** + * Opens an index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html + * + * @param array{ + * index: list, // (REQUIRED) A comma separated list of indices to open + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * wait_for_active_shards: string, // Sets the number of active shards to wait for before the operation 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 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 open(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_open'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','wait_for_active_shards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Promotes a data stream from a replicated data stream managed by CCR to a regular data stream + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the data stream + * 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 promoteDataStream(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_data_stream/_promote/' . $this->encode($params['name']); + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates or updates an alias. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names the alias should point to (supports wildcards); use `_all` to perform the operation on all indices. + * name: string, // (REQUIRED) The name of the alias to be created or updated + * timeout: time, // Explicit timestamp for the document + * master_timeout: time, // Specify timeout for connection to master + * 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, // The settings for the alias, such as `routing` or `filter` + * } $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 putAlias(array $params = []) + { + $this->checkRequiredParameters(['index','name'], $params); + $url = '/' . $this->encode($params['index']) . '/_alias/' . $this->encode($params['name']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['timeout','master_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)); + } + + + /** + * Creates or updates an index template. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * create: boolean, // Whether the index template should only be added if new or can also replace an existing one + * cause: string, // User defined reason for creating/updating the index template + * master_timeout: time, // Specify timeout for connection to master + * 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 template definition + * } $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 putIndexTemplate(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_index_template/' . $this->encode($params['name']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['create','cause','master_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)); + } + + + /** + * Updates the index mappings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices. + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * write_index_only: boolean, // When true, applies mappings only to the write index of an alias or data stream + * 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 mapping definition + * } $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 putMapping(array $params = []) + { + $this->checkRequiredParameters(['index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_mapping'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','write_index_only','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)); + } + + + /** + * Updates the index settings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * master_timeout: time, // Specify timeout for connection to master + * timeout: time, // Explicit operation timeout + * preserve_existing: boolean, // Whether to update existing settings. If set to `true` existing settings on an index remain unchanged, the default is `false` + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * flat_settings: boolean, // Return settings in flat format (default: false) + * 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 index settings to be updated + * } $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 putSettings(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_settings'; + $method = 'PUT'; + } else { + $url = '/_settings'; + $method = 'PUT'; + } + $url = $this->addQueryString($url, $params, ['master_timeout','timeout','preserve_existing','ignore_unavailable','allow_no_indices','expand_wildcards','flat_settings','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)); + } + + + /** + * Creates or updates an index template. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the template + * order: number, // The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers) + * create: boolean, // Whether the index template should only be added if new or can also replace an existing one + * master_timeout: time, // Specify timeout for connection to master + * 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 template definition + * } $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 putTemplate(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_template/' . $this->encode($params['name']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['order','create','master_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)); + } + + + /** + * Returns information about ongoing index shard recoveries. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * detailed: boolean, // Whether to display detailed information about shard recovery + * active_only: boolean, // Display only those recoveries that are currently on-going + * 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 recovery(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_recovery'; + $method = 'GET'; + } else { + $url = '/_recovery'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['detailed','active_only','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Performs the refresh operation in one or more indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 refresh(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_refresh'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_refresh'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Reloads an index's search analyzers and their resources. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-reload-analyzers.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names to reload analyzers for + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 reloadSearchAnalyzers(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_reload_search_analyzers'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about any matching indices, aliases, and data streams + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-resolve-index-api.html + * + * @param array{ + * name: list, // (REQUIRED) A comma-separated list of names or wildcard expressions + * expand_wildcards: enum, // Whether wildcard expressions should get expanded to open or closed indices (default: open) + * 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 resolveIndex(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_resolve/index/' . $this->encode($params['name']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Updates an alias to point to a new index when the existing index + * is considered to be too large or too old. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html + * + * @param array{ + * alias: string, // (REQUIRED) The name of the alias to rollover + * new_index: string, // The name of the rollover index + * timeout: time, // Explicit operation timeout + * dry_run: boolean, // If set to true the rollover action will only be validated but not actually performed even if a condition matches. The default is false + * master_timeout: time, // Specify timeout for connection to master + * wait_for_active_shards: string, // Set the number of active shards to wait for on the newly created rollover index before the operation 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. + * body: array, // The conditions that needs to be met for executing rollover + * } $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 rollover(array $params = []) + { + $this->checkRequiredParameters(['alias'], $params); + if (isset($params['new_index'])) { + $url = '/' . $this->encode($params['alias']) . '/_rollover/' . $this->encode($params['new_index']); + $method = 'POST'; + } else { + $url = '/' . $this->encode($params['alias']) . '/_rollover'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['timeout','dry_run','master_timeout','wait_for_active_shards','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)); + } + + + /** + * Provides low-level information about segments in a Lucene index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * verbose: boolean, // Includes detailed memory usage by Lucene. + * 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 segments(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_segments'; + $method = 'GET'; + } else { + $url = '/_segments'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','verbose','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Provides store information for shard copies of indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * status: list, // A comma-separated list of statuses used to filter on shards to get store information for + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 shardStores(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_shard_stores'; + $method = 'GET'; + } else { + $url = '/_shard_stores'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['status','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allow to shrink an existing index into a new index with fewer primary shards. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the source index to shrink + * target: string, // (REQUIRED) The name of the target index to shrink into + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * wait_for_active_shards: string, // Set the number of active shards to wait for on the shrunken index before the operation 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. + * body: array, // The configuration for the target index (`settings` and `aliases`) + * } $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 shrink(array $params = []) + { + $this->checkRequiredParameters(['index','target'], $params); + $url = '/' . $this->encode($params['index']) . '/_shrink/' . $this->encode($params['target']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','wait_for_active_shards','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)); + } + + + /** + * Simulate matching the given index name against the index templates in the system + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // (REQUIRED) The name of the index (it must be a concrete index name) + * create: boolean, // Whether the index template we optionally defined in the body should only be dry-run added if new or can also replace an existing one + * cause: string, // User defined reason for dry-run creating the new template for simulation purposes + * master_timeout: time, // Specify timeout for connection to master + * 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, // New index template definition, which will be included in the simulation, as if it already exists in the system + * } $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 simulateIndexTemplate(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_index_template/_simulate_index/' . $this->encode($params['name']); + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['create','cause','master_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)); + } + + + /** + * Simulate resolving the given template name or body + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + * + * @param array{ + * name: string, // The name of the index template + * create: boolean, // Whether the index template we optionally defined in the body should only be dry-run added if new or can also replace an existing one + * cause: string, // User defined reason for dry-run creating the new template for simulation purposes + * master_timeout: time, // Specify timeout for connection to master + * 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, // New index template definition to be simulated, if no index template name is specified + * } $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 simulateTemplate(array $params = []) + { + if (isset($params['name'])) { + $url = '/_index_template/_simulate/' . $this->encode($params['name']); + $method = 'POST'; + } else { + $url = '/_index_template/_simulate'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['create','cause','master_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)); + } + + + /** + * Allows you to split an existing index into a new index with more primary shards. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-split-index.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the source index to split + * target: string, // (REQUIRED) The name of the target index to split into + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * wait_for_active_shards: string, // Set the number of active shards to wait for on the shrunken index before the operation 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. + * body: array, // The configuration for the target index (`settings` and `aliases`) + * } $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 split(array $params = []) + { + $this->checkRequiredParameters(['index','target'], $params); + $url = '/' . $this->encode($params['index']) . '/_split/' . $this->encode($params['target']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','wait_for_active_shards','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)); + } + + + /** + * Provides statistics on operations happening in an index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html + * + * @param array{ + * metric: list, // Limit the information returned the specific metrics. + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * completion_fields: list, // A comma-separated list of fields for the `completion` index metric (supports wildcards) + * fielddata_fields: list, // A comma-separated list of fields for the `fielddata` index metric (supports wildcards) + * fields: list, // A comma-separated list of fields for `fielddata` and `completion` index metric (supports wildcards) + * groups: list, // A comma-separated list of search groups for `search` index metric + * level: enum, // Return stats aggregated at cluster, index or shard level + * include_segment_file_sizes: boolean, // Whether to report the aggregated disk usage of each one of the Lucene index files (only applies if segment stats are requested) + * include_unloaded_segments: boolean, // If set to true segment stats will include stats for segments that are not currently loaded into memory + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * forbid_closed_indices: boolean, // If set to false stats will also collected from closed indices if explicitly specified or if expand_wildcards expands to closed indices + * 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 stats(array $params = []) + { + if (isset($params['index']) && isset($params['metric'])) { + $url = '/' . $this->encode($params['index']) . '/_stats/' . $this->encode($params['metric']); + $method = 'GET'; + } elseif (isset($params['metric'])) { + $url = '/_stats/' . $this->encode($params['metric']); + $method = 'GET'; + } elseif (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_stats'; + $method = 'GET'; + } else { + $url = '/_stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['completion_fields','fielddata_fields','fields','groups','level','include_segment_file_sizes','include_unloaded_segments','expand_wildcards','forbid_closed_indices','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Unfreezes an index. When a frozen index is unfrozen, the index goes through the normal recovery process and becomes writeable again. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/unfreeze-index-api.html + * + * @param array{ + * index: string, // (REQUIRED) The name of the index to unfreeze + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * wait_for_active_shards: string, // Sets the number of active shards to wait for before the operation 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 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 unfreeze(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_unfreeze'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','ignore_unavailable','allow_no_indices','expand_wildcards','wait_for_active_shards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Updates index aliases. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + * + * @param array{ + * timeout: time, // Request timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 definition of `actions` to perform + * } $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 updateAliases(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_aliases'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['timeout','master_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)); + } + + + /** + * Allows a user to validate a potentially expensive query without executing it. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html + * + * @param array{ + * index: list, // A comma-separated list of index names to restrict the operation; use `_all` or empty string to perform the operation on all indices + * explain: boolean, // Return detailed information about the error + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * q: string, // Query in the Lucene query string syntax + * analyzer: string, // The analyzer to use for the query string + * analyze_wildcard: boolean, // Specify whether wildcard and prefix queries should be analyzed (default: false) + * default_operator: enum, // The default operator for query string query (AND or OR) + * df: string, // The field to use as default where no field prefix is given in the query string + * lenient: boolean, // Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * rewrite: boolean, // Provide a more detailed explanation showing the actual Lucene query that will be executed. + * all_shards: boolean, // Execute validation on all shards instead of one random shard per index + * 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, // The query definition specified with the Query DSL + * } $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 validateQuery(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_validate/query'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_validate/query'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['explain','ignore_unavailable','allow_no_indices','expand_wildcards','q','analyzer','analyze_wildcard','default_operator','df','lenient','rewrite','all_shards','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Ingest.php b/Elastic/Elasticsearch/Endpoints/Ingest.php new file mode 100644 index 0000000..1208435 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Ingest.php @@ -0,0 +1,250 @@ +checkRequiredParameters(['id'], $params); + $url = '/_ingest/pipeline/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['master_timeout','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns statistical information about geoip databases + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/geoip-stats-api.html + * + * @param array{ + * 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 geoIpStats(array $params = []) + { + $url = '/_ingest/geoip/stats'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a pipeline. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/get-pipeline-api.html + * + * @param array{ + * id: string, // Comma separated list of pipeline ids. Wildcards supported + * summary: boolean, // Return pipelines without their definitions (default: false) + * master_timeout: time, // Explicit operation timeout for connection to master node + * 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 getPipeline(array $params = []) + { + if (isset($params['id'])) { + $url = '/_ingest/pipeline/' . $this->encode($params['id']); + $method = 'GET'; + } else { + $url = '/_ingest/pipeline'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['summary','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a list of the built-in patterns. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/grok-processor.html#grok-processor-rest-get + * + * @param array{ + * 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 processorGrok(array $params = []) + { + $url = '/_ingest/processor/grok'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates or updates a pipeline. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/put-pipeline-api.html + * + * @param array{ + * id: string, // (REQUIRED) Pipeline ID + * if_version: int, // Required version for optimistic concurrency control for pipeline updates + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * 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 ingest definition + * } $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 putPipeline(array $params = []) + { + $this->checkRequiredParameters(['id','body'], $params); + $url = '/_ingest/pipeline/' . $this->encode($params['id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['if_version','master_timeout','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)); + } + + + /** + * Allows to simulate a pipeline with example documents. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/simulate-pipeline-api.html + * + * @param array{ + * id: string, // Pipeline ID + * verbose: boolean, // Verbose mode. Display data output for each processor in executed pipeline + * 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 simulate definition + * } $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 simulate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['id'])) { + $url = '/_ingest/pipeline/' . $this->encode($params['id']) . '/_simulate'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ingest/pipeline/_simulate'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['verbose','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/License.php b/Elastic/Elasticsearch/Endpoints/License.php new file mode 100644 index 0000000..75cbbfc --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/License.php @@ -0,0 +1,261 @@ +addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves licensing information for the cluster + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/get-license.html + * + * @param array{ + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * accept_enterprise: boolean, // Supported for backwards compatibility with 7.x. If this param is used it must be set to true + * 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 get(array $params = []) + { + $url = '/_license'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['local','accept_enterprise','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves information about the status of the basic license. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/get-basic-status.html + * + * @param array{ + * 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 getBasicStatus(array $params = []) + { + $url = '/_license/basic_status'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves information about the status of the trial license. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/get-trial-status.html + * + * @param array{ + * 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 getTrialStatus(array $params = []) + { + $url = '/_license/trial_status'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Updates the license for the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/update-license.html + * + * @param array{ + * acknowledge: boolean, // whether the user has acknowledged acknowledge messages (default: false) + * 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, // licenses to be installed + * } $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 post(array $params = []) + { + $url = '/_license'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['acknowledge','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 an indefinite basic license. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/start-basic.html + * + * @param array{ + * acknowledge: boolean, // whether the user has acknowledged acknowledge messages (default: false) + * 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 postStartBasic(array $params = []) + { + $url = '/_license/start_basic'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['acknowledge','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * starts a limited time trial license. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/start-trial.html + * + * @param array{ + * type: string, // The type of trial license to generate (default: "trial") + * acknowledge: boolean, // whether the user has acknowledged acknowledge messages (default: false) + * 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 postStartTrial(array $params = []) + { + $url = '/_license/start_trial'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['type','acknowledge','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Logstash.php b/Elastic/Elasticsearch/Endpoints/Logstash.php new file mode 100644 index 0000000..7e83ae3 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Logstash.php @@ -0,0 +1,136 @@ +checkRequiredParameters(['id'], $params); + $url = '/_logstash/pipeline/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves Logstash Pipelines used by Central Management + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/logstash-api-get-pipeline.html + * + * @param array{ + * id: string, // (REQUIRED) A comma-separated list of Pipeline IDs + * 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 getPipeline(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_logstash/pipeline/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Adds and updates Logstash Pipelines used for Central Management + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/logstash-api-put-pipeline.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the Pipeline + * 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 Pipeline to add or update + * } $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 putPipeline(array $params = []) + { + $this->checkRequiredParameters(['id','body'], $params); + $url = '/_logstash/pipeline/' . $this->encode($params['id']); + $method = 'PUT'; + + $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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Migration.php b/Elastic/Elasticsearch/Endpoints/Migration.php new file mode 100644 index 0000000..ccbbe40 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Migration.php @@ -0,0 +1,130 @@ +encode($params['index']) . '/_migration/deprecations'; + $method = 'GET'; + } else { + $url = '/_migration/deprecations'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Find out whether system features need to be upgraded or not + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-feature-upgrade.html + * + * @param array{ + * 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 getFeatureUpgradeStatus(array $params = []) + { + $url = '/_migration/system_features'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Begin upgrades for system features + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-feature-upgrade.html + * + * @param array{ + * 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 postFeatureUpgrade(array $params = []) + { + $url = '/_migration/system_features'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Ml.php b/Elastic/Elasticsearch/Endpoints/Ml.php new file mode 100644 index 0000000..eeee939 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Ml.php @@ -0,0 +1,2826 @@ +checkRequiredParameters(['model_id'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/deployment/cache/_clear'; + $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)); + } + + + /** + * Closes one or more anomaly detection jobs. A job can be opened and closed multiple times throughout its lifecycle. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-close-job.html + * + * @param array{ + * job_id: string, // (REQUIRED) The name of the job to close + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + * force: boolean, // True if the job should be forcefully closed + * timeout: time, // Controls the time to wait until a job has closed. Default to 30 minutes + * 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, // The URL params optionally sent in the body + * } $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 closeJob(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_close'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['allow_no_match','force','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)); + } + + + /** + * Deletes a calendar. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-calendar.html + * + * @param array{ + * calendar_id: string, // (REQUIRED) The ID of the calendar to delete + * 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 deleteCalendar(array $params = []) + { + $this->checkRequiredParameters(['calendar_id'], $params); + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes scheduled events from a calendar. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-calendar-event.html + * + * @param array{ + * calendar_id: string, // (REQUIRED) The ID of the calendar to modify + * event_id: string, // (REQUIRED) The ID of the event to remove from the calendar + * 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 deleteCalendarEvent(array $params = []) + { + $this->checkRequiredParameters(['calendar_id','event_id'], $params); + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']) . '/events/' . $this->encode($params['event_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes anomaly detection jobs from a calendar. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-calendar-job.html + * + * @param array{ + * calendar_id: string, // (REQUIRED) The ID of the calendar to modify + * job_id: string, // (REQUIRED) The ID of the job to remove from the calendar + * 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 deleteCalendarJob(array $params = []) + { + $this->checkRequiredParameters(['calendar_id','job_id'], $params); + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']) . '/jobs/' . $this->encode($params['job_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an existing data frame analytics job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-dfanalytics.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the data frame analytics to delete + * force: boolean, // True if the job should be forcefully deleted + * timeout: time, // Controls the time to wait until a job is deleted. Defaults to 1 minute + * 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 deleteDataFrameAnalytics(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['force','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an existing datafeed. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html + * + * @param array{ + * datafeed_id: string, // (REQUIRED) The ID of the datafeed to delete + * force: boolean, // True if the datafeed should be forcefully 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) + * 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 deleteDatafeed(array $params = []) + { + $this->checkRequiredParameters(['datafeed_id'], $params); + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['force','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes expired and unused machine learning data. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-expired-data.html + * + * @param array{ + * job_id: string, // The ID of the job(s) to perform expired data hygiene for + * requests_per_second: number, // The desired requests per second for the deletion processes. + * timeout: time, // How long can the underlying delete processes run until they are canceled + * 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, // deleting expired data parameters + * } $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 deleteExpiredData(array $params = []) + { + if (isset($params['job_id'])) { + $url = '/_ml/_delete_expired_data/' . $this->encode($params['job_id']); + $method = 'DELETE'; + } else { + $url = '/_ml/_delete_expired_data'; + $method = 'DELETE'; + } + $url = $this->addQueryString($url, $params, ['requests_per_second','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)); + } + + + /** + * Deletes a filter. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-filter.html + * + * @param array{ + * filter_id: string, // (REQUIRED) The ID of the filter to delete + * 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 deleteFilter(array $params = []) + { + $this->checkRequiredParameters(['filter_id'], $params); + $url = '/_ml/filters/' . $this->encode($params['filter_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes forecasts from a machine learning job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job from which to delete forecasts + * forecast_id: string, // The ID of the forecast to delete, can be comma delimited list. Leaving blank implies `_all` + * allow_no_forecasts: boolean, // Whether to ignore if `_all` matches no forecasts + * timeout: time, // Controls the time to wait until the forecast(s) are deleted. Default to 30 seconds + * 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 deleteForecast(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + if (isset($params['forecast_id'])) { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_forecast/' . $this->encode($params['forecast_id']); + $method = 'DELETE'; + } else { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_forecast'; + $method = 'DELETE'; + } + $url = $this->addQueryString($url, $params, ['allow_no_forecasts','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an existing anomaly detection job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html + * + * @param array{ + * 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 + * 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 deleteJob(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $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']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an existing model snapshot. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-snapshot.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to fetch + * snapshot_id: string, // (REQUIRED) The ID of the snapshot to delete + * 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 deleteModelSnapshot(array $params = []) + { + $this->checkRequiredParameters(['job_id','snapshot_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/model_snapshots/' . $this->encode($params['snapshot_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes an existing trained inference model that is currently not referenced by an ingest pipeline. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-trained-models.html + * + * @param array{ + * model_id: string, // (REQUIRED) The ID of the trained model to delete + * timeout: time, // Controls the amount of time to wait for the model to be deleted. + * force: boolean, // True if the model should be forcefully 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) + * 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 deleteTrainedModel(array $params = []) + { + $this->checkRequiredParameters(['model_id'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['timeout','force','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes a model alias that refers to the trained model + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-trained-models-aliases.html + * + * @param array{ + * model_alias: string, // (REQUIRED) The trained model alias to delete + * model_id: string, // (REQUIRED) The trained model where the model alias is assigned + * 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 deleteTrainedModelAlias(array $params = []) + { + $this->checkRequiredParameters(['model_alias','model_id'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/model_aliases/' . $this->encode($params['model_alias']); + $method = 'DELETE'; + + $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)); + } + + + /** + * Estimates the model memory + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-apis.html + * + * @param array{ + * 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 analysis config, plus cardinality estimates for fields it references + * } $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 estimateModelMemory(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_ml/anomaly_detectors/_estimate_model_memory'; + $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)); + } + + + /** + * Evaluates the data frame analytics for an annotated index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/evaluate-dfanalytics.html + * + * @param array{ + * 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 evaluation definition + * } $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 evaluateDataFrame(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_ml/data_frame/_evaluate'; + $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)); + } + + + /** + * Explains a data frame analytics config. + * + * @see http://www.elastic.co/guide/en/elasticsearch/reference/current/explain-dfanalytics.html + * + * @param array{ + * id: string, // The ID of the data frame analytics to explain + * 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, // The data frame analytics config to explain + * } $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 explainDataFrameAnalytics(array $params = []) + { + if (isset($params['id'])) { + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']) . '/_explain'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ml/data_frame/analytics/_explain'; + $method = empty($params['body']) ? 'GET' : '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)); + } + + + /** + * Forces any buffered data to be processed by the job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html + * + * @param array{ + * job_id: string, // (REQUIRED) The name of the job to flush + * calc_interim: boolean, // Calculates interim results for the most recent bucket or all buckets within the latency period + * start: string, // When used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results + * end: string, // When used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results + * advance_time: string, // Advances time to the given value generating results and updating the model for the advanced interval + * skip_time: string, // Skips time to the given value without generating results or updating the model for the skipped interval + * 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, // Flush parameters + * } $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 flushJob(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_flush'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['calc_interim','start','end','advance_time','skip_time','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)); + } + + + /** + * Predicts the future behavior of a time series by using its historical behavior. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-forecast.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to forecast for + * duration: time, // The duration of the forecast + * expires_in: time, // The time interval after which the forecast expires. Expired forecasts will be deleted at the first opportunity. + * max_model_memory: string, // The max memory able to be used by the forecast. Default is 20mb. + * 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, // Query parameters can be specified in the body + * } $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 forecast(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_forecast'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['duration','expires_in','max_model_memory','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)); + } + + + /** + * Retrieves anomaly detection job results for one or more buckets. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-bucket.html + * + * @param array{ + * job_id: string, // (REQUIRED) ID of the job to get bucket results from + * timestamp: string, // The timestamp of the desired single bucket result + * expand: boolean, // Include anomaly records + * exclude_interim: boolean, // Exclude interim results + * from: int, // skips a number of buckets + * size: int, // specifies a max number of buckets to get + * start: string, // Start time filter for buckets + * end: string, // End time filter for buckets + * anomaly_score: double, // Filter for the most anomalous buckets + * sort: string, // Sort buckets by a particular field + * desc: boolean, // Set the sort direction + * 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, // Bucket selection details if not provided in URI + * } $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 getBuckets(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + if (isset($params['timestamp'])) { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/results/buckets/' . $this->encode($params['timestamp']); + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/results/buckets'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['expand','exclude_interim','from','size','start','end','anomaly_score','sort','desc','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)); + } + + + /** + * Retrieves information about the scheduled events in calendars. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-calendar-event.html + * + * @param array{ + * calendar_id: string, // (REQUIRED) The ID of the calendar containing the events + * job_id: string, // Get events for the job. When this option is used calendar_id must be '_all' + * start: string, // Get events after this time + * end: date, // Get events before this time + * from: int, // Skips a number of events + * size: int, // Specifies a max number of events to get + * 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 getCalendarEvents(array $params = []) + { + $this->checkRequiredParameters(['calendar_id'], $params); + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']) . '/events'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['job_id','start','end','from','size','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves configuration information for calendars. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-calendar.html + * + * @param array{ + * calendar_id: string, // The ID of the calendar to fetch + * from: int, // skips a number of calendars + * size: int, // specifies a max number of calendars to get + * 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, // The from and size parameters optionally sent in the body + * } $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 getCalendars(array $params = []) + { + if (isset($params['calendar_id'])) { + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']); + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ml/calendars'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['from','size','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)); + } + + + /** + * Retrieves anomaly detection job results for one or more categories. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-category.html + * + * @param array{ + * job_id: string, // (REQUIRED) The name of the job + * category_id: long, // The identifier of the category definition of interest + * from: int, // skips a number of categories + * size: int, // specifies a max number of categories to get + * partition_field_value: string, // Specifies the partition to retrieve categories for. This is optional, and should never be used for jobs where per-partition categorization is disabled. + * 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, // Category selection details if not provided in URI + * } $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 getCategories(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + if (isset($params['category_id'])) { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/results/categories/' . $this->encode($params['category_id']); + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/results/categories/'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['from','size','partition_field_value','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)); + } + + + /** + * Retrieves configuration information for data frame analytics jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-dfanalytics.html + * + * @param array{ + * id: string, // The ID of the data frame analytics to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no data frame analytics. (This includes `_all` string or when no data frame analytics have been specified) + * from: int, // skips a number of analytics + * size: int, // specifies a max number of analytics to get + * exclude_generated: boolean, // Omits fields that are illegal to set on data frame analytics PUT + * 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 getDataFrameAnalytics(array $params = []) + { + if (isset($params['id'])) { + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']); + $method = 'GET'; + } else { + $url = '/_ml/data_frame/analytics'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','from','size','exclude_generated','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves usage information for data frame analytics jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-dfanalytics-stats.html + * + * @param array{ + * id: string, // The ID of the data frame analytics stats to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no data frame analytics. (This includes `_all` string or when no data frame analytics have been specified) + * from: int, // skips a number of analytics + * size: int, // specifies a max number of analytics to get + * verbose: boolean, // whether the stats response should be verbose + * 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 getDataFrameAnalyticsStats(array $params = []) + { + if (isset($params['id'])) { + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']) . '/_stats'; + $method = 'GET'; + } else { + $url = '/_ml/data_frame/analytics/_stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','from','size','verbose','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves usage information for datafeeds. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed-stats.html + * + * @param array{ + * datafeed_id: string, // The ID of the datafeeds stats to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + * 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 getDatafeedStats(array $params = []) + { + if (isset($params['datafeed_id'])) { + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']) . '/_stats'; + $method = 'GET'; + } else { + $url = '/_ml/datafeeds/_stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves configuration information for datafeeds. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed.html + * + * @param array{ + * datafeed_id: string, // The ID of the datafeeds to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + * exclude_generated: boolean, // Omits fields that are illegal to set on datafeed PUT + * 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 getDatafeeds(array $params = []) + { + if (isset($params['datafeed_id'])) { + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']); + $method = 'GET'; + } else { + $url = '/_ml/datafeeds'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','exclude_generated','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves filters. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-filter.html + * + * @param array{ + * filter_id: string, // The ID of the filter to fetch + * from: int, // skips a number of filters + * size: int, // specifies a max number of filters to get + * 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 getFilters(array $params = []) + { + if (isset($params['filter_id'])) { + $url = '/_ml/filters/' . $this->encode($params['filter_id']); + $method = 'GET'; + } else { + $url = '/_ml/filters'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['from','size','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves anomaly detection job results for one or more influencers. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-influencer.html + * + * @param array{ + * job_id: string, // (REQUIRED) Identifier for the anomaly detection job + * exclude_interim: boolean, // Exclude interim results + * from: int, // skips a number of influencers + * size: int, // specifies a max number of influencers to get + * start: string, // start timestamp for the requested influencers + * end: string, // end timestamp for the requested influencers + * influencer_score: double, // influencer score threshold for the requested influencers + * sort: string, // sort field for the requested influencers + * desc: boolean, // whether the results should be sorted in decending order + * 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, // Influencer selection criteria + * } $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 getInfluencers(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/results/influencers'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['exclude_interim','from','size','start','end','influencer_score','sort','desc','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)); + } + + + /** + * Retrieves usage information for anomaly detection jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html + * + * @param array{ + * job_id: string, // The ID of the jobs stats to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + * 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 getJobStats(array $params = []) + { + if (isset($params['job_id'])) { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_stats'; + $method = 'GET'; + } else { + $url = '/_ml/anomaly_detectors/_stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves configuration information for anomaly detection jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job.html + * + * @param array{ + * job_id: string, // The ID of the jobs to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + * exclude_generated: boolean, // Omits fields that are illegal to set on job PUT + * 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 getJobs(array $params = []) + { + if (isset($params['job_id'])) { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']); + $method = 'GET'; + } else { + $url = '/_ml/anomaly_detectors'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','exclude_generated','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information on how ML is using memory. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-ml-memory.html + * + * @param array{ + * node_id: string, // Specifies the node or nodes to retrieve stats for. + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * 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 getMemoryStats(array $params = []) + { + if (isset($params['node_id'])) { + $url = '/_ml/memory/' . $this->encode($params['node_id']) . '/_stats'; + $method = 'GET'; + } else { + $url = '/_ml/memory/_stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['master_timeout','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Gets stats for anomaly detection job model snapshot upgrades that are in progress. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-model-snapshot-upgrade-stats.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job. May be a wildcard, comma separated list or `_all`. + * snapshot_id: string, // (REQUIRED) The ID of the snapshot. May be a wildcard, comma separated list or `_all`. + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no jobs or no snapshots. (This includes the `_all` string.) + * 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 getModelSnapshotUpgradeStats(array $params = []) + { + $this->checkRequiredParameters(['job_id','snapshot_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/model_snapshots/' . $this->encode($params['snapshot_id']) . '/_upgrade/_stats'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['allow_no_match','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves information about model snapshots. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-snapshot.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to fetch + * snapshot_id: string, // The ID of the snapshot to fetch + * from: int, // Skips a number of documents + * size: int, // The default number of documents returned in queries as a string. + * start: date, // The filter 'start' query parameter + * end: date, // The filter 'end' query parameter + * sort: string, // Name of the field to sort on + * desc: boolean, // True if the results should be sorted in descending order + * 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, // Model snapshot selection criteria + * } $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 getModelSnapshots(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + if (isset($params['snapshot_id'])) { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/model_snapshots/' . $this->encode($params['snapshot_id']); + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/model_snapshots'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['from','size','start','end','sort','desc','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)); + } + + + /** + * Retrieves overall bucket results that summarize the bucket results of multiple anomaly detection jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-overall-buckets.html + * + * @param array{ + * job_id: string, // (REQUIRED) The job IDs for which to calculate overall bucket results + * top_n: int, // The number of top job bucket scores to be used in the overall_score calculation + * bucket_span: string, // The span of the overall buckets. Defaults to the longest job bucket_span + * overall_score: double, // Returns overall buckets with overall scores higher than this value + * exclude_interim: boolean, // If true overall buckets that include interim buckets will be excluded + * start: string, // Returns overall buckets with timestamps after this time + * end: string, // Returns overall buckets with timestamps earlier than this time + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + * 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, // Overall bucket selection details if not provided in URI + * } $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 getOverallBuckets(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/results/overall_buckets'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['top_n','bucket_span','overall_score','exclude_interim','start','end','allow_no_match','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)); + } + + + /** + * Retrieves anomaly records for an anomaly detection job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-record.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job + * exclude_interim: boolean, // Exclude interim results + * from: int, // skips a number of records + * size: int, // specifies a max number of records to get + * start: string, // Start time filter for records + * end: string, // End time filter for records + * record_score: double, // Returns records with anomaly scores greater or equal than this value + * sort: string, // Sort records by a particular field + * desc: boolean, // Set the sort direction + * 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, // Record selection criteria + * } $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 getRecords(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/results/records'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['exclude_interim','from','size','start','end','record_score','sort','desc','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)); + } + + + /** + * Retrieves configuration information for a trained inference model. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-trained-models.html + * + * @param array{ + * model_id: string, // The ID of the trained models to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no trained models. (This includes `_all` string or when no trained models have been specified) + * include: string, // A comma-separate list of fields to optionally include. Valid options are 'definition' and 'total_feature_importance'. Default is none. + * include_model_definition: boolean, // Should the full model definition be included in the results. These definitions can be large. So be cautious when including them. Defaults to false. + * decompress_definition: boolean, // Should the model definition be decompressed into valid JSON or returned in a custom compressed format. Defaults to true. + * from: int, // skips a number of trained models + * size: int, // specifies a max number of trained models to get + * tags: list, // A comma-separated list of tags that the model must have. + * exclude_generated: boolean, // Omits fields that are illegal to set on model PUT + * 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 getTrainedModels(array $params = []) + { + if (isset($params['model_id'])) { + $url = '/_ml/trained_models/' . $this->encode($params['model_id']); + $method = 'GET'; + } else { + $url = '/_ml/trained_models'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','include','include_model_definition','decompress_definition','from','size','tags','exclude_generated','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves usage information for trained inference models. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-trained-models-stats.html + * + * @param array{ + * model_id: string, // The ID of the trained models stats to fetch + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no trained models. (This includes `_all` string or when no trained models have been specified) + * from: int, // skips a number of trained models + * size: int, // specifies a max number of trained models to get + * 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 getTrainedModelsStats(array $params = []) + { + if (isset($params['model_id'])) { + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/_stats'; + $method = 'GET'; + } else { + $url = '/_ml/trained_models/_stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['allow_no_match','from','size','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Evaluate a trained model. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/infer-trained-model.html + * + * @param array{ + * model_id: string, // (REQUIRED) The unique identifier of the trained model. + * timeout: time, // Controls the amount of time to wait for inference results. + * 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 docs to apply inference on and inference configuration overrides + * } $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 inferTrainedModel(array $params = []) + { + $this->checkRequiredParameters(['model_id','body'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/_infer'; + $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)); + } + + + /** + * Returns defaults and limits used by machine learning. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-ml-info.html + * + * @param array{ + * 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 info(array $params = []) + { + $url = '/_ml/info'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Opens one or more anomaly detection jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to open + * 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, // Query parameters can be specified in the body + * } $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 openJob(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_open'; + $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)); + } + + + /** + * Posts scheduled events in a calendar. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-calendar-event.html + * + * @param array{ + * calendar_id: string, // (REQUIRED) The ID of the calendar to modify + * 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) A list of events + * } $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 postCalendarEvents(array $params = []) + { + $this->checkRequiredParameters(['calendar_id','body'], $params); + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']) . '/events'; + $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)); + } + + + /** + * Sends data to an anomaly detection job for analysis. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-data.html + * + * @param array{ + * job_id: string, // (REQUIRED) The name of the job receiving the data + * reset_start: string, // Optional parameter to specify the start of the bucket resetting range + * reset_end: string, // Optional parameter to specify the end of the bucket resetting range + * 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 data to process + * } $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 postData(array $params = []) + { + $this->checkRequiredParameters(['job_id','body'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_data'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['reset_start','reset_end','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => isset($params['body']) && (is_string($params['body']) || $this->isAssociativeArray($params['body'])) ? 'application/json' : 'application/x-ndjson', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Previews that will be analyzed given a data frame analytics config. + * + * @see http://www.elastic.co/guide/en/elasticsearch/reference/current/preview-dfanalytics.html + * + * @param array{ + * id: string, // The ID of the data frame analytics to preview + * 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, // The data frame analytics config to preview + * } $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 previewDataFrameAnalytics(array $params = []) + { + if (isset($params['id'])) { + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']) . '/_preview'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ml/data_frame/analytics/_preview'; + $method = empty($params['body']) ? 'GET' : '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)); + } + + + /** + * Previews a datafeed. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-preview-datafeed.html + * + * @param array{ + * datafeed_id: string, // The ID of the datafeed to preview + * start: string, // The start time from where the datafeed preview should begin + * end: string, // The end time when the datafeed preview should stop + * 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, // The datafeed config and job config with which to execute the preview + * } $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 previewDatafeed(array $params = []) + { + if (isset($params['datafeed_id'])) { + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']) . '/_preview'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_ml/datafeeds/_preview'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['start','end','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)); + } + + + /** + * Instantiates a calendar. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-calendar.html + * + * @param array{ + * calendar_id: string, // (REQUIRED) The ID of the calendar to create + * 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, // The calendar details + * } $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 putCalendar(array $params = []) + { + $this->checkRequiredParameters(['calendar_id'], $params); + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']); + $method = 'PUT'; + + $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)); + } + + + /** + * Adds an anomaly detection job to a calendar. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-calendar-job.html + * + * @param array{ + * calendar_id: string, // (REQUIRED) The ID of the calendar to modify + * job_id: string, // (REQUIRED) The ID of the job to add to the calendar + * 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 putCalendarJob(array $params = []) + { + $this->checkRequiredParameters(['calendar_id','job_id'], $params); + $url = '/_ml/calendars/' . $this->encode($params['calendar_id']) . '/jobs/' . $this->encode($params['job_id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Instantiates a data frame analytics job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-dfanalytics.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the data frame analytics to create + * 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 data frame analytics configuration + * } $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 putDataFrameAnalytics(array $params = []) + { + $this->checkRequiredParameters(['id','body'], $params); + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']); + $method = 'PUT'; + + $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)); + } + + + /** + * Instantiates a datafeed. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-datafeed.html + * + * @param array{ + * datafeed_id: string, // (REQUIRED) The ID of the datafeed to create + * ignore_unavailable: boolean, // Ignore unavailable indexes (default: false) + * allow_no_indices: boolean, // Ignore if the source indices expressions resolves to no concrete indices (default: true) + * ignore_throttled: boolean, // Ignore indices that are marked as throttled (default: true) + * expand_wildcards: enum, // Whether source index expressions should get expanded to open or closed indices (default: open) + * 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 datafeed config + * } $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 putDatafeed(array $params = []) + { + $this->checkRequiredParameters(['datafeed_id','body'], $params); + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','ignore_throttled','expand_wildcards','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)); + } + + + /** + * Instantiates a filter. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-filter.html + * + * @param array{ + * filter_id: string, // (REQUIRED) The ID of the filter to create + * 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 filter details + * } $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 putFilter(array $params = []) + { + $this->checkRequiredParameters(['filter_id','body'], $params); + $url = '/_ml/filters/' . $this->encode($params['filter_id']); + $method = 'PUT'; + + $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)); + } + + + /** + * Instantiates an anomaly detection job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-job.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to create + * ignore_unavailable: boolean, // Ignore unavailable indexes (default: false). Only set if datafeed_config is provided. + * allow_no_indices: boolean, // Ignore if the source indices expressions resolves to no concrete indices (default: true). Only set if datafeed_config is provided. + * ignore_throttled: boolean, // Ignore indices that are marked as throttled (default: true). Only set if datafeed_config is provided. + * expand_wildcards: enum, // Whether source index expressions should get expanded to open or closed indices (default: open). Only set if datafeed_config is provided. + * 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 job + * } $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 putJob(array $params = []) + { + $this->checkRequiredParameters(['job_id','body'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','ignore_throttled','expand_wildcards','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)); + } + + + /** + * Creates an inference trained model. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-trained-models.html + * + * @param array{ + * model_id: string, // (REQUIRED) The ID of the trained models to store + * defer_definition_decompression: boolean, // If set to `true` and a `compressed_definition` is provided, the request defers definition decompression and skips relevant validations. + * 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 trained model configuration + * } $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 putTrainedModel(array $params = []) + { + $this->checkRequiredParameters(['model_id','body'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['defer_definition_decompression','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)); + } + + + /** + * Creates a new model alias (or reassigns an existing one) to refer to the trained model + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-trained-models-aliases.html + * + * @param array{ + * model_alias: string, // (REQUIRED) The trained model alias to update + * model_id: string, // (REQUIRED) The trained model where the model alias should be assigned + * reassign: boolean, // If the model_alias already exists and points to a separate model_id, this parameter must be true. Defaults to false. + * 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 putTrainedModelAlias(array $params = []) + { + $this->checkRequiredParameters(['model_alias','model_id'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/model_aliases/' . $this->encode($params['model_alias']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['reassign','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)); + } + + + /** + * Creates part of a trained model definition + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-trained-model-definition-part.html + * + * @param array{ + * model_id: string, // (REQUIRED) The ID of the trained model for this definition part + * part: int, // (REQUIRED) The part number + * 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 trained model definition part + * } $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 putTrainedModelDefinitionPart(array $params = []) + { + $this->checkRequiredParameters(['model_id','part','body'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/definition/' . $this->encode($params['part']); + $method = 'PUT'; + + $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)); + } + + + /** + * Creates a trained model vocabulary + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-trained-model-vocabulary.html + * + * @param array{ + * model_id: string, // (REQUIRED) The ID of the trained model for this vocabulary + * 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 trained model vocabulary + * } $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 putTrainedModelVocabulary(array $params = []) + { + $this->checkRequiredParameters(['model_id','body'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/vocabulary'; + $method = 'PUT'; + + $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)); + } + + + /** + * Resets an existing anomaly detection job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-reset-job.html + * + * @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 + * 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 resetJob(array $params = []) + { + $this->checkRequiredParameters(['job_id'], $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']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Reverts to a specific snapshot. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-revert-snapshot.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to fetch + * snapshot_id: string, // (REQUIRED) The ID of the snapshot to revert to + * delete_intervening_results: boolean, // Should we reset the results back to the time of the snapshot? + * 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, // Reversion options + * } $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 revertModelSnapshot(array $params = []) + { + $this->checkRequiredParameters(['job_id','snapshot_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/model_snapshots/' . $this->encode($params['snapshot_id']) . '/_revert'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['delete_intervening_results','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)); + } + + + /** + * Sets a cluster wide upgrade_mode setting that prepares machine learning indices for an upgrade. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-set-upgrade-mode.html + * + * @param array{ + * enabled: boolean, // Whether to enable upgrade_mode ML setting or not. Defaults to false. + * timeout: time, // Controls the time to wait before action times out. Defaults to 30 seconds + * 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 setUpgradeMode(array $params = []) + { + $url = '/_ml/set_upgrade_mode'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['enabled','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Starts a data frame analytics job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/start-dfanalytics.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the data frame analytics to start + * timeout: time, // Controls the time to wait until the task has started. Defaults to 20 seconds + * 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, // The start data frame analytics parameters + * } $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 startDataFrameAnalytics(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']) . '/_start'; + $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 datafeeds. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-start-datafeed.html + * + * @param array{ + * datafeed_id: string, // (REQUIRED) The ID of the datafeed to start + * start: string, // The start time from where the datafeed should begin + * end: string, // The end time when the datafeed should stop. When not set, the datafeed continues in real time + * timeout: time, // Controls the time to wait until a datafeed has started. Default to 20 seconds + * 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, // The start datafeed parameters + * } $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 startDatafeed(array $params = []) + { + $this->checkRequiredParameters(['datafeed_id'], $params); + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']) . '/_start'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['start','end','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)); + } + + + /** + * Start a trained model deployment. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/start-trained-model-deployment.html + * + * @param array{ + * model_id: string, // (REQUIRED) The unique identifier of the trained model. + * 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. + * 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 + * 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 startTrainedModelDeployment(array $params = []) + { + $this->checkRequiredParameters(['model_id'], $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']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Stops one or more data frame analytics jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-dfanalytics.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the data frame analytics to stop + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no data frame analytics. (This includes `_all` string or when no data frame analytics have been specified) + * force: boolean, // True if the data frame analytics should be forcefully stopped + * timeout: time, // Controls the time to wait until the task has stopped. Defaults to 20 seconds + * 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, // The stop data frame analytics parameters + * } $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 stopDataFrameAnalytics(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']) . '/_stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['allow_no_match','force','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)); + } + + + /** + * Stops one or more datafeeds. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-stop-datafeed.html + * + * @param array{ + * datafeed_id: string, // (REQUIRED) The ID of the datafeed to stop + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + * allow_no_datafeeds: boolean, // Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + * force: boolean, // True if the datafeed should be forcefully stopped. + * timeout: time, // Controls the time to wait until a datafeed has stopped. Default to 20 seconds + * 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, // The URL params optionally sent in the body + * } $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 stopDatafeed(array $params = []) + { + $this->checkRequiredParameters(['datafeed_id'], $params); + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']) . '/_stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['allow_no_match','allow_no_datafeeds','force','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)); + } + + + /** + * Stop a trained model deployment. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/stop-trained-model-deployment.html + * + * @param array{ + * model_id: string, // (REQUIRED) The unique identifier of the trained model. + * allow_no_match: boolean, // Whether to ignore if a wildcard expression matches no deployments. (This includes `_all` string or when no deployments have been specified) + * force: boolean, // True if the deployment should be forcefully stopped + * 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, // The stop deployment parameters + * } $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 stopTrainedModelDeployment(array $params = []) + { + $this->checkRequiredParameters(['model_id'], $params); + $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/deployment/_stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['allow_no_match','force','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)); + } + + + /** + * Updates certain properties of a data frame analytics job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/update-dfanalytics.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the data frame analytics to update + * 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 data frame analytics settings to update + * } $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 updateDataFrameAnalytics(array $params = []) + { + $this->checkRequiredParameters(['id','body'], $params); + $url = '/_ml/data_frame/analytics/' . $this->encode($params['id']) . '/_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)); + } + + + /** + * Updates certain properties of a datafeed. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-datafeed.html + * + * @param array{ + * datafeed_id: string, // (REQUIRED) The ID of the datafeed to update + * ignore_unavailable: boolean, // Ignore unavailable indexes (default: false) + * allow_no_indices: boolean, // Ignore if the source indices expressions resolves to no concrete indices (default: true) + * ignore_throttled: boolean, // Ignore indices that are marked as throttled (default: true) + * expand_wildcards: enum, // Whether source index expressions should get expanded to open or closed indices (default: open) + * 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 datafeed update 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 updateDatafeed(array $params = []) + { + $this->checkRequiredParameters(['datafeed_id','body'], $params); + $url = '/_ml/datafeeds/' . $this->encode($params['datafeed_id']) . '/_update'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','ignore_throttled','expand_wildcards','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)); + } + + + /** + * Updates the description of a filter, adds items, or removes items. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-filter.html + * + * @param array{ + * filter_id: string, // (REQUIRED) The ID of the filter to update + * 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 filter update + * } $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 updateFilter(array $params = []) + { + $this->checkRequiredParameters(['filter_id','body'], $params); + $url = '/_ml/filters/' . $this->encode($params['filter_id']) . '/_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)); + } + + + /** + * Updates certain properties of an anomaly detection job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-job.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to create + * 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 job update 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 updateJob(array $params = []) + { + $this->checkRequiredParameters(['job_id','body'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/_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)); + } + + + /** + * Updates certain properties of a snapshot. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-snapshot.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job to fetch + * snapshot_id: string, // (REQUIRED) The ID of the snapshot to update + * 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 model snapshot properties to update + * } $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 updateModelSnapshot(array $params = []) + { + $this->checkRequiredParameters(['job_id','snapshot_id','body'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/model_snapshots/' . $this->encode($params['snapshot_id']) . '/_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. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-upgrade-job-model-snapshot.html + * + * @param array{ + * job_id: string, // (REQUIRED) The ID of the job + * snapshot_id: string, // (REQUIRED) The ID of the snapshot + * timeout: time, // How long should the API wait for the job to be opened and the old snapshot to be loaded. + * wait_for_completion: boolean, // Should the request wait until the task is complete before responding to the caller. Default is false. + * 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 upgradeJobSnapshot(array $params = []) + { + $this->checkRequiredParameters(['job_id','snapshot_id'], $params); + $url = '/_ml/anomaly_detectors/' . $this->encode($params['job_id']) . '/model_snapshots/' . $this->encode($params['snapshot_id']) . '/_upgrade'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['timeout','wait_for_completion','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Validates an anomaly detection job. + * + * @see https://www.elastic.co/guide/en/machine-learning/current/ml-jobs.html + * + * @param array{ + * 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 job config + * } $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 validate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_ml/anomaly_detectors/_validate'; + $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)); + } + + + /** + * Validates an anomaly detection detector. + * + * @see https://www.elastic.co/guide/en/machine-learning/current/ml-jobs.html + * + * @param array{ + * 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 detector + * } $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 validateDetector(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_ml/anomaly_detectors/_validate/detector'; + $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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Monitoring.php b/Elastic/Elasticsearch/Endpoints/Monitoring.php new file mode 100644 index 0000000..ff4185c --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Monitoring.php @@ -0,0 +1,72 @@ +checkRequiredParameters(['body'], $params); + if (isset($params['type'])) { + $url = '/_monitoring/' . $this->encode($params['type']) . '/bulk'; + $method = 'POST'; + } else { + $url = '/_monitoring/bulk'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['system_id','system_api_version','interval','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/x-ndjson', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Nodes.php b/Elastic/Elasticsearch/Endpoints/Nodes.php new file mode 100644 index 0000000..7af1b03 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Nodes.php @@ -0,0 +1,337 @@ +checkRequiredParameters(['node_id','max_archive_version'], $params); + $url = '/_nodes/' . $this->encode($params['node_id']) . '/_repositories_metering/' . $this->encode($params['max_archive_version']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns cluster repositories metering information. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-repositories-metering-api.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * node_id: list, // (REQUIRED) A comma-separated list of node IDs or names to limit the returned information. + * 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 getRepositoriesMeteringInfo(array $params = []) + { + $this->checkRequiredParameters(['node_id'], $params); + $url = '/_nodes/' . $this->encode($params['node_id']) . '/_repositories_metering'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about hot threads on each node in the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html + * + * @param array{ + * node_id: list, // A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * interval: time, // The interval for the second sampling of threads + * snapshots: number, // Number of samples of thread stacktrace (default: 10) + * threads: number, // Specify the number of threads to provide information for (default: 3) + * ignore_idle_threads: boolean, // Don't show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue (default: true) + * type: enum, // The type to sample (default: cpu) + * sort: enum, // The sort order for 'cpu' type (default: total) + * timeout: time, // Explicit operation timeout + * 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 hotThreads(array $params = []) + { + if (isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/hot_threads'; + $method = 'GET'; + } else { + $url = '/_nodes/hot_threads'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['interval','snapshots','threads','ignore_idle_threads','type','sort','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'text/plain', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about nodes in the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html + * + * @param array{ + * node_id: list, // A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * metric: list, // A comma-separated list of metrics you wish returned. Use `_all` to retrieve all metrics and `_none` to retrieve the node identity without any additional metrics. + * flat_settings: boolean, // Return settings in flat format (default: false) + * timeout: time, // Explicit operation timeout + * 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 info(array $params = []) + { + if (isset($params['node_id']) && isset($params['metric'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/' . $this->encode($params['metric']); + $method = 'GET'; + } elseif (isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']); + $method = 'GET'; + } elseif (isset($params['metric'])) { + $url = '/_nodes/' . $this->encode($params['metric']); + $method = 'GET'; + } else { + $url = '/_nodes'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['flat_settings','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Reloads secure settings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/secure-settings.html#reloadable-secure-settings + * + * @param array{ + * node_id: list, // A comma-separated list of node IDs to span the reload/reinit call. Should stay empty because reloading usually involves all cluster nodes. + * timeout: time, // Explicit operation timeout + * 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, // An object containing the password for the elasticsearch keystore + * } $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 reloadSecureSettings(array $params = []) + { + if (isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/reload_secure_settings'; + $method = 'POST'; + } else { + $url = '/_nodes/reload_secure_settings'; + $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)); + } + + + /** + * Returns statistical information about nodes in the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html + * + * @param array{ + * node_id: list, // A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * metric: list, // Limit the information returned to the specified metrics + * index_metric: list, // Limit the information returned for `indices` metric to the specific index metrics. Isn't used if `indices` (or `all`) metric isn't specified. + * completion_fields: list, // A comma-separated list of fields for the `completion` index metric (supports wildcards) + * fielddata_fields: list, // A comma-separated list of fields for the `fielddata` index metric (supports wildcards) + * fields: list, // A comma-separated list of fields for `fielddata` and `completion` index metric (supports wildcards) + * groups: boolean, // A comma-separated list of search groups for `search` index metric + * level: enum, // Return indices stats aggregated at index, node or shard level + * types: list, // A comma-separated list of document types for the `indexing` index metric + * timeout: time, // Explicit operation timeout + * include_segment_file_sizes: boolean, // Whether to report the aggregated disk usage of each one of the Lucene index files (only applies if segment stats are requested) + * include_unloaded_segments: boolean, // If set to true segment stats will include stats for segments that are not currently loaded into memory + * 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 stats(array $params = []) + { + if (isset($params['metric']) && isset($params['index_metric']) && isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/stats/' . $this->encode($params['metric']) . '/' . $this->encode($params['index_metric']); + $method = 'GET'; + } elseif (isset($params['metric']) && isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/stats/' . $this->encode($params['metric']); + $method = 'GET'; + } elseif (isset($params['metric']) && isset($params['index_metric'])) { + $url = '/_nodes/stats/' . $this->encode($params['metric']) . '/' . $this->encode($params['index_metric']); + $method = 'GET'; + } elseif (isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/stats'; + $method = 'GET'; + } elseif (isset($params['metric'])) { + $url = '/_nodes/stats/' . $this->encode($params['metric']); + $method = 'GET'; + } else { + $url = '/_nodes/stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['completion_fields','fielddata_fields','fields','groups','level','types','timeout','include_segment_file_sizes','include_unloaded_segments','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns low-level information about REST actions usage on nodes. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html + * + * @param array{ + * node_id: list, // A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * metric: list, // Limit the information returned to the specified metrics + * timeout: time, // Explicit operation timeout + * 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 usage(array $params = []) + { + if (isset($params['metric']) && isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/usage/' . $this->encode($params['metric']); + $method = 'GET'; + } elseif (isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/usage'; + $method = 'GET'; + } elseif (isset($params['metric'])) { + $url = '/_nodes/usage/' . $this->encode($params['metric']); + $method = 'GET'; + } else { + $url = '/_nodes/usage'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Rollup.php b/Elastic/Elasticsearch/Endpoints/Rollup.php new file mode 100644 index 0000000..4fe55d0 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Rollup.php @@ -0,0 +1,329 @@ +checkRequiredParameters(['id'], $params); + $url = '/_rollup/job/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves the configuration, stats, and status of rollup jobs. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-job.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * id: string, // The ID of the job(s) to fetch. Accepts glob patterns, or left blank for all jobs + * 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 getJobs(array $params = []) + { + if (isset($params['id'])) { + $url = '/_rollup/job/' . $this->encode($params['id']); + $method = 'GET'; + } else { + $url = '/_rollup/job/'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the capabilities of any rollup jobs that have been configured for a specific index or index pattern. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-caps.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * id: string, // The ID of the index to check rollup capabilities on, or left blank for all jobs + * 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 getRollupCaps(array $params = []) + { + if (isset($params['id'])) { + $url = '/_rollup/data/' . $this->encode($params['id']); + $method = 'GET'; + } else { + $url = '/_rollup/data/'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the rollup capabilities of all jobs inside of a rollup index (e.g. the index where rollup data is stored). + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: string, // (REQUIRED) The rollup index or index pattern to obtain rollup capabilities from. + * 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 getRollupIndexCaps(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_rollup/data'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a rollup job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-put-job.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * id: string, // (REQUIRED) The ID of the job to create + * 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 job configuration + * } $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 putJob(array $params = []) + { + $this->checkRequiredParameters(['id','body'], $params); + $url = '/_rollup/job/' . $this->encode($params['id']); + $method = 'PUT'; + + $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)); + } + + + /** + * Enables searching rolled-up data using the standard query DSL. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-search.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: list, // (REQUIRED) The indices or index-pattern(s) (containing rollup or regular data) that should be searched + * typed_keys: boolean, // Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * rest_total_hits_as_int: boolean, // Indicates whether hits.total should be rendered as an integer or an object in the rest search response + * 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 search request body + * } $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 rollupSearch(array $params = []) + { + $this->checkRequiredParameters(['index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_rollup_search'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['typed_keys','rest_total_hits_as_int','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 an existing, stopped rollup job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-start-job.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * id: string, // (REQUIRED) The ID of the job to start + * 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 startJob(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_rollup/job/' . $this->encode($params['id']) . '/_start'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Stops an existing, started rollup job. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-stop-job.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * id: string, // (REQUIRED) The ID of the job to stop + * wait_for_completion: boolean, // True if the API should block until the job has fully stopped, false if should be executed async. Defaults to false. + * timeout: time, // Block for (at maximum) the specified duration while waiting for the job to stop. Defaults to 30s. + * 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 stopJob(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_rollup/job/' . $this->encode($params['id']) . '/_stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['wait_for_completion','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/SearchableSnapshots.php b/Elastic/Elasticsearch/Endpoints/SearchableSnapshots.php new file mode 100644 index 0000000..aae90e6 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/SearchableSnapshots.php @@ -0,0 +1,187 @@ +encode($params['node_id']) . '/cache/stats'; + $method = 'GET'; + } else { + $url = '/_searchable_snapshots/cache/stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Clear the cache of searchable snapshots. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-apis.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: list, // A comma-separated list of index names + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 clearCache(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_searchable_snapshots/cache/clear'; + $method = 'POST'; + } else { + $url = '/_searchable_snapshots/cache/clear'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Mount a snapshot as a searchable index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-api-mount-snapshot.html + * + * @param array{ + * repository: string, // (REQUIRED) The name of the repository containing the snapshot of the index to mount + * snapshot: string, // (REQUIRED) The name of the snapshot of the index to mount + * master_timeout: time, // Explicit operation timeout for connection to master node + * wait_for_completion: boolean, // Should this request wait until the operation has completed before returning + * storage: string, // Selects the kind of local storage used to accelerate searches. Experimental, and defaults to `full_copy` + * 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 restore configuration for mounting the snapshot as searchable + * } $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 mount(array $params = []) + { + $this->checkRequiredParameters(['repository','snapshot','body'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']) . '/_mount'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['master_timeout','wait_for_completion','storage','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)); + } + + + /** + * Retrieve shard-level statistics about searchable snapshots. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-apis.html + * + * @param array{ + * index: list, // A comma-separated list of index names + * level: enum, // Return stats aggregated at cluster, index or shard level + * 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 stats(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_searchable_snapshots/stats'; + $method = 'GET'; + } else { + $url = '/_searchable_snapshots/stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['level','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Security.php b/Elastic/Elasticsearch/Endpoints/Security.php new file mode 100644 index 0000000..f5acec6 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Security.php @@ -0,0 +1,2018 @@ +checkRequiredParameters(['body'], $params); + $url = '/_security/profile/_activate'; + $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)); + } + + + /** + * Enables authentication as a user and retrieve information about the authenticated user. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-authenticate.html + * + * @param array{ + * 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 authenticate(array $params = []) + { + $url = '/_security/_authenticate'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Updates the attributes of multiple existing API keys. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-bulk-update-api-keys.html + * + * @param array{ + * 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 API key request to update the attributes of multiple API keys. + * } $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 bulkUpdateApiKeys(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/api_key/_bulk_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)); + } + + + /** + * Changes the passwords of users in the native realm and built-in users. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html + * + * @param array{ + * username: string, // The username of the user to change the password for + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 new password for the user + * } $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 changePassword(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['username'])) { + $url = '/_security/user/' . $this->encode($params['username']) . '/_password'; + $method = 'PUT'; + } else { + $url = '/_security/user/_password'; + $method = 'PUT'; + } + $url = $this->addQueryString($url, $params, ['refresh','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)); + } + + + /** + * Clear a subset or all entries from the API key cache. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-api-key-cache.html + * + * @param array{ + * ids: list, // (REQUIRED) A comma-separated list of IDs of API keys to clear from the cache + * 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 clearApiKeyCache(array $params = []) + { + $this->checkRequiredParameters(['ids'], $params); + $url = '/_security/api_key/' . $this->encode($params['ids']) . '/_clear_cache'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Evicts application privileges from the native application privileges cache. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-privilege-cache.html + * + * @param array{ + * application: list, // (REQUIRED) A comma-separated list of application names + * 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 clearCachedPrivileges(array $params = []) + { + $this->checkRequiredParameters(['application'], $params); + $url = '/_security/privilege/' . $this->encode($params['application']) . '/_clear_cache'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Evicts users from the user cache. Can completely clear the cache or evict specific users. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-cache.html + * + * @param array{ + * realms: list, // (REQUIRED) Comma-separated list of realms to clear + * usernames: list, // Comma-separated list of usernames to clear from the cache + * 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 clearCachedRealms(array $params = []) + { + $this->checkRequiredParameters(['realms'], $params); + $url = '/_security/realm/' . $this->encode($params['realms']) . '/_clear_cache'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['usernames','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Evicts roles from the native role cache. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-role-cache.html + * + * @param array{ + * name: list, // (REQUIRED) Role name + * 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 clearCachedRoles(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_security/role/' . $this->encode($params['name']) . '/_clear_cache'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Evicts tokens from the service account token caches. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-service-token-caches.html + * + * @param array{ + * namespace: string, // (REQUIRED) An identifier for the namespace + * service: string, // (REQUIRED) An identifier for the service name + * name: list, // (REQUIRED) A comma-separated list of service token names + * 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 clearCachedServiceTokens(array $params = []) + { + $this->checkRequiredParameters(['namespace','service','name'], $params); + $url = '/_security/service/' . $this->encode($params['namespace']) . '/' . $this->encode($params['service']) . '/credential/token/' . $this->encode($params['name']) . '/_clear_cache'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates an API key for access without requiring basic authentication. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html + * + * @param array{ + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 api key request to create an API key + * } $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 createApiKey(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/api_key'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','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)); + } + + + /** + * Creates a service account token for access without requiring basic authentication. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-service-token.html + * + * @param array{ + * namespace: string, // (REQUIRED) An identifier for the namespace + * service: string, // (REQUIRED) An identifier for the service name + * name: string, // An identifier for the token name + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` (the default) then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 createServiceToken(array $params = []) + { + $this->checkRequiredParameters(['namespace','service'], $params); + if (isset($params['name'])) { + $url = '/_security/service/' . $this->encode($params['namespace']) . '/' . $this->encode($params['service']) . '/credential/token/' . $this->encode($params['name']); + $method = 'PUT'; + } else { + $url = '/_security/service/' . $this->encode($params['namespace']) . '/' . $this->encode($params['service']) . '/credential/token'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Removes application privileges. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-privilege.html + * + * @param array{ + * application: string, // (REQUIRED) Application name + * name: string, // (REQUIRED) Privilege name + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 deletePrivileges(array $params = []) + { + $this->checkRequiredParameters(['application','name'], $params); + $url = '/_security/privilege/' . $this->encode($params['application']) . '/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Removes roles in the native realm. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role.html + * + * @param array{ + * name: string, // (REQUIRED) Role name + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 deleteRole(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_security/role/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Removes role mappings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role-mapping.html + * + * @param array{ + * name: string, // (REQUIRED) Role-mapping name + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 deleteRoleMapping(array $params = []) + { + $this->checkRequiredParameters(['name'], $params); + $url = '/_security/role_mapping/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes a service account token. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-service-token.html + * + * @param array{ + * namespace: string, // (REQUIRED) An identifier for the namespace + * service: string, // (REQUIRED) An identifier for the service name + * name: string, // (REQUIRED) An identifier for the token name + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` (the default) then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 deleteServiceToken(array $params = []) + { + $this->checkRequiredParameters(['namespace','service','name'], $params); + $url = '/_security/service/' . $this->encode($params['namespace']) . '/' . $this->encode($params['service']) . '/credential/token/' . $this->encode($params['name']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes users from the native realm. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-user.html + * + * @param array{ + * username: string, // (REQUIRED) username + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 deleteUser(array $params = []) + { + $this->checkRequiredParameters(['username'], $params); + $url = '/_security/user/' . $this->encode($params['username']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Disables users in the native realm. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html + * + * @param array{ + * username: string, // (REQUIRED) The username of the user to disable + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 disableUser(array $params = []) + { + $this->checkRequiredParameters(['username'], $params); + $url = '/_security/user/' . $this->encode($params['username']) . '/_disable'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Disables a user profile so it's not visible in user profile searches. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-disable-user-profile.html + * + * @param array{ + * uid: string, // (REQUIRED) Unique identifier for the user profile + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` (the default) then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 disableUserProfile(array $params = []) + { + $this->checkRequiredParameters(['uid'], $params); + $url = '/_security/profile/' . $this->encode($params['uid']) . '/_disable'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Enables users in the native realm. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html + * + * @param array{ + * username: string, // (REQUIRED) The username of the user to enable + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 enableUser(array $params = []) + { + $this->checkRequiredParameters(['username'], $params); + $url = '/_security/user/' . $this->encode($params['username']) . '/_enable'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Enables a user profile so it's visible in user profile searches. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-enable-user-profile.html + * + * @param array{ + * uid: string, // (REQUIRED) An unique identifier of the user profile + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` (the default) then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 enableUserProfile(array $params = []) + { + $this->checkRequiredParameters(['uid'], $params); + $url = '/_security/profile/' . $this->encode($params['uid']) . '/_enable'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows a kibana instance to configure itself to communicate with a secured elasticsearch cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-kibana-enrollment.html + * + * @param array{ + * 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 enrollKibana(array $params = []) + { + $url = '/_security/enroll/kibana'; + $method = 'GET'; + + $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)); + } + + + /** + * Allows a new node to enroll to an existing cluster with security enabled. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-node-enrollment.html + * + * @param array{ + * 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 enrollNode(array $params = []) + { + $url = '/_security/enroll/node'; + $method = 'GET'; + + $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)); + } + + + /** + * Retrieves information for one or more API keys. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-api-key.html + * + * @param array{ + * id: string, // API key id of the API key to be retrieved + * name: string, // API key name of the API key to be retrieved + * username: string, // user name of the user who created this API key to be retrieved + * realm_name: string, // realm name of the user who created this API key to be retrieved + * owner: boolean, // flag to query API keys owned by the currently authenticated user + * with_limited_by: boolean, // flag to show the limited-by role descriptors of API Keys + * 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 getApiKey(array $params = []) + { + $url = '/_security/api_key'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['id','name','username','realm_name','owner','with_limited_by','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves the list of cluster privileges and index privileges that are available in this version of Elasticsearch. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-builtin-privileges.html + * + * @param array{ + * 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 getBuiltinPrivileges(array $params = []) + { + $url = '/_security/privilege/_builtin'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves application privileges. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-privileges.html + * + * @param array{ + * application: string, // Application name + * name: string, // Privilege name + * 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 getPrivileges(array $params = []) + { + if (isset($params['application']) && isset($params['name'])) { + $url = '/_security/privilege/' . $this->encode($params['application']) . '/' . $this->encode($params['name']); + $method = 'GET'; + } elseif (isset($params['application'])) { + $url = '/_security/privilege/' . $this->encode($params['application']); + $method = 'GET'; + } else { + $url = '/_security/privilege'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves roles in the native realm. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role.html + * + * @param array{ + * name: list, // A comma-separated list of role names + * 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 getRole(array $params = []) + { + if (isset($params['name'])) { + $url = '/_security/role/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_security/role'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves role mappings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role-mapping.html + * + * @param array{ + * name: list, // A comma-separated list of role-mapping names + * 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 getRoleMapping(array $params = []) + { + if (isset($params['name'])) { + $url = '/_security/role_mapping/' . $this->encode($params['name']); + $method = 'GET'; + } else { + $url = '/_security/role_mapping'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves information about service accounts. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-service-accounts.html + * + * @param array{ + * namespace: string, // An identifier for the namespace + * service: string, // An identifier for the service name + * 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 getServiceAccounts(array $params = []) + { + if (isset($params['namespace']) && isset($params['service'])) { + $url = '/_security/service/' . $this->encode($params['namespace']) . '/' . $this->encode($params['service']); + $method = 'GET'; + } elseif (isset($params['namespace'])) { + $url = '/_security/service/' . $this->encode($params['namespace']); + $method = 'GET'; + } else { + $url = '/_security/service'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves information of all service credentials for a service account. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-service-credentials.html + * + * @param array{ + * namespace: string, // (REQUIRED) An identifier for the namespace + * service: string, // (REQUIRED) An identifier for the service name + * 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 getServiceCredentials(array $params = []) + { + $this->checkRequiredParameters(['namespace','service'], $params); + $url = '/_security/service/' . $this->encode($params['namespace']) . '/' . $this->encode($params['service']) . '/credential'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a bearer token for access without requiring basic authentication. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-token.html + * + * @param array{ + * 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 token request to get + * } $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 getToken(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/oauth2/token'; + $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)); + } + + + /** + * Retrieves information about users in the native realm and built-in users. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-user.html + * + * @param array{ + * username: list, // A comma-separated list of usernames + * with_profile_uid: boolean, // flag to retrieve profile uid (if exists) associated to the user + * 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 getUser(array $params = []) + { + if (isset($params['username'])) { + $url = '/_security/user/' . $this->encode($params['username']); + $method = 'GET'; + } else { + $url = '/_security/user'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['with_profile_uid','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves security privileges for the logged in user. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-user-privileges.html + * + * @param array{ + * 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 getUserPrivileges(array $params = []) + { + $url = '/_security/user/_privileges'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves user profiles for the given unique ID(s). + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-user-profile.html + * + * @param array{ + * uid: list, // (REQUIRED) A comma-separated list of unique identifier for user profiles + * data: list, // A comma-separated list of keys for which the corresponding application data are retrieved. + * 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 getUserProfile(array $params = []) + { + $this->checkRequiredParameters(['uid'], $params); + $url = '/_security/profile/' . $this->encode($params['uid']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['data','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates an API key on behalf of another user. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-grant-api-key.html + * + * @param array{ + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 api key request to create an API key + * } $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 grantApiKey(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/api_key/grant'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['refresh','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)); + } + + + /** + * Determines whether the specified user has a specified list of privileges. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-has-privileges.html + * + * @param array{ + * user: string, // Username + * 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 privileges to test + * } $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 hasPrivileges(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['user'])) { + $url = '/_security/user/' . $this->encode($params['user']) . '/_has_privileges'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_security/user/_has_privileges'; + $method = empty($params['body']) ? 'GET' : '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)); + } + + + /** + * Determines whether the users associated with the specified profile IDs have all the requested privileges. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-has-privileges-user-profile.html + * + * @param array{ + * 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 privileges to check and the list of profile IDs + * } $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 hasPrivilegesUserProfile(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/profile/_has_privileges'; + $method = empty($params['body']) ? 'GET' : '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)); + } + + + /** + * Invalidates one or more API keys. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-api-key.html + * + * @param array{ + * 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 api key request to invalidate API key(s) + * } $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 invalidateApiKey(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/api_key'; + $method = 'DELETE'; + + $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)); + } + + + /** + * Invalidates one or more access tokens or refresh tokens. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-token.html + * + * @param array{ + * 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 token to invalidate + * } $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 invalidateToken(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/oauth2/token'; + $method = 'DELETE'; + + $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)); + } + + + /** + * Exchanges an OpenID Connection authentication response message for an Elasticsearch access token and refresh token pair + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-oidc-authenticate.html + * + * @param array{ + * 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 OpenID Connect response to authenticate + * } $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 oidcAuthenticate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/oidc/authenticate'; + $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)); + } + + + /** + * Invalidates a refresh token and access token that was generated from the OpenID Connect Authenticate API + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-oidc-logout.html + * + * @param array{ + * 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) Access token and refresh token to invalidate + * } $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 oidcLogout(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/oidc/logout'; + $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)); + } + + + /** + * Creates an OAuth 2.0 authentication request as a URL string + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-oidc-prepare-authentication.html + * + * @param array{ + * 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 OpenID Connect authentication realm configuration + * } $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 oidcPrepareAuthentication(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/oidc/prepare'; + $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)); + } + + + /** + * Adds or updates application privileges. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-privileges.html + * + * @param array{ + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 privilege(s) to add + * } $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 putPrivileges(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/privilege/'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','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)); + } + + + /** + * Adds and updates roles in the native realm. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role.html + * + * @param array{ + * name: string, // (REQUIRED) Role name + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 role to add + * } $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 putRole(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_security/role/' . $this->encode($params['name']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','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)); + } + + + /** + * Creates and updates role mappings. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role-mapping.html + * + * @param array{ + * name: string, // (REQUIRED) Role-mapping name + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 role mapping to add + * } $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 putRoleMapping(array $params = []) + { + $this->checkRequiredParameters(['name','body'], $params); + $url = '/_security/role_mapping/' . $this->encode($params['name']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','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)); + } + + + /** + * Adds and updates users in the native realm. These users are commonly referred to as native users. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-user.html + * + * @param array{ + * username: string, // (REQUIRED) The username of the User + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 user to add + * } $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 putUser(array $params = []) + { + $this->checkRequiredParameters(['username','body'], $params); + $url = '/_security/user/' . $this->encode($params['username']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['refresh','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)); + } + + + /** + * Retrieves information for API keys using a subset of query DSL + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-query-api-key.html + * + * @param array{ + * with_limited_by: boolean, // flag to show the limited-by role descriptors of API Keys + * 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, // From, size, query, sort and search_after + * } $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 queryApiKeys(array $params = []) + { + $url = '/_security/_query/api_key'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['with_limited_by','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)); + } + + + /** + * Exchanges a SAML Response message for an Elasticsearch access token and refresh token pair + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-saml-authenticate.html + * + * @param array{ + * 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 SAML response to authenticate + * } $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 samlAuthenticate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/saml/authenticate'; + $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)); + } + + + /** + * Verifies the logout response sent from the SAML IdP + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-saml-complete-logout.html + * + * @param array{ + * 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 logout response to verify + * } $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 samlCompleteLogout(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/saml/complete_logout'; + $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)); + } + + + /** + * Consumes a SAML LogoutRequest + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-saml-invalidate.html + * + * @param array{ + * 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 LogoutRequest message + * } $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 samlInvalidate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/saml/invalidate'; + $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)); + } + + + /** + * Invalidates an access token and a refresh token that were generated via the SAML Authenticate API + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-saml-logout.html + * + * @param array{ + * 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 tokens to invalidate + * } $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 samlLogout(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/saml/logout'; + $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)); + } + + + /** + * Creates a SAML authentication request + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-saml-prepare-authentication.html + * + * @param array{ + * 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 realm for which to create the authentication request, identified by either its name or the ACS URL + * } $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 samlPrepareAuthentication(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_security/saml/prepare'; + $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)); + } + + + /** + * Generates SAML metadata for the Elastic stack SAML 2.0 Service Provider + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-saml-sp-metadata.html + * + * @param array{ + * realm_name: string, // (REQUIRED) The name of the SAML realm to get the metadata for + * 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 samlServiceProviderMetadata(array $params = []) + { + $this->checkRequiredParameters(['realm_name'], $params); + $url = '/_security/saml/metadata/' . $this->encode($params['realm_name']); + $method = 'GET'; + + $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)); + } + + + /** + * Get suggestions for user profiles that match specified search criteria. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/security-api-suggest-user-profile.html + * + * @param array{ + * data: list, // A comma-separated list of keys for which the corresponding application data are retrieved. + * 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, // The suggestion definition for user profiles + * } $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 suggestUserProfiles(array $params = []) + { + $url = '/_security/profile/_suggest'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['data','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)); + } + + + /** + * Updates attributes of an existing API key. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-update-api-key.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the API key to update + * 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, // The API key request to update attributes of an API key. + * } $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 updateApiKey(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_security/api_key/' . $this->encode($params['id']); + $method = 'PUT'; + + $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)); + } + + + /** + * Update application specific data for the user profile of the given unique ID. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-update-user-profile-data.html + * + * @param array{ + * uid: string, // (REQUIRED) An unique identifier of the user profile + * if_seq_no: number, // only perform the update operation if the last operation that has changed the document has the specified sequence number + * if_primary_term: number, // only perform the update operation if the last operation that has changed the document has the specified primary term + * refresh: enum, // If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * 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 application data to update + * } $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 updateUserProfileData(array $params = []) + { + $this->checkRequiredParameters(['uid','body'], $params); + $url = '/_security/profile/' . $this->encode($params['uid']) . '/_data'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['if_seq_no','if_primary_term','refresh','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Shutdown.php b/Elastic/Elasticsearch/Endpoints/Shutdown.php new file mode 100644 index 0000000..2c9e55e --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Shutdown.php @@ -0,0 +1,140 @@ +checkRequiredParameters(['node_id'], $params); + $url = '/_nodes/' . $this->encode($params['node_id']) . '/shutdown'; + $method = 'DELETE'; + + $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)); + } + + + /** + * Retrieve status of a node or nodes that are currently marked as shutting down. Designed for indirect use by ECE/ESS and ECK. Direct use is not supported. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current + * + * @param array{ + * node_id: string, // Which node for which to retrieve the shutdown status + * 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 getNode(array $params = []) + { + if (isset($params['node_id'])) { + $url = '/_nodes/' . $this->encode($params['node_id']) . '/shutdown'; + $method = 'GET'; + } else { + $url = '/_nodes/shutdown'; + $method = 'GET'; + } + $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)); + } + + + /** + * Adds a node to be shut down. Designed for indirect use by ECE/ESS and ECK. Direct use is not supported. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current + * + * @param array{ + * node_id: string, // (REQUIRED) The node id of node to be shut down + * 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 shutdown type definition to register + * } $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 putNode(array $params = []) + { + $this->checkRequiredParameters(['node_id','body'], $params); + $url = '/_nodes/' . $this->encode($params['node_id']) . '/shutdown'; + $method = 'PUT'; + + $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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Slm.php b/Elastic/Elasticsearch/Endpoints/Slm.php new file mode 100644 index 0000000..2050a37 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Slm.php @@ -0,0 +1,333 @@ +checkRequiredParameters(['policy_id'], $params); + $url = '/_slm/policy/' . $this->encode($params['policy_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Immediately creates a snapshot according to the lifecycle policy, without waiting for the scheduled time. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute-lifecycle.html + * + * @param array{ + * policy_id: string, // (REQUIRED) The id of the snapshot lifecycle policy to be executed + * 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 executeLifecycle(array $params = []) + { + $this->checkRequiredParameters(['policy_id'], $params); + $url = '/_slm/policy/' . $this->encode($params['policy_id']) . '/_execute'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes any snapshots that are expired according to the policy's retention rules. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute-retention.html + * + * @param array{ + * 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 executeRetention(array $params = []) + { + $url = '/_slm/_execute_retention'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves one or more snapshot lifecycle policy definitions and information about the latest snapshot attempts. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get-policy.html + * + * @param array{ + * policy_id: list, // Comma-separated list of snapshot lifecycle policies to retrieve + * 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 getLifecycle(array $params = []) + { + if (isset($params['policy_id'])) { + $url = '/_slm/policy/' . $this->encode($params['policy_id']); + $method = 'GET'; + } else { + $url = '/_slm/policy'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns global and policy-level statistics about actions taken by snapshot lifecycle management. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/slm-api-get-stats.html + * + * @param array{ + * 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 getStats(array $params = []) + { + $url = '/_slm/stats'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves the status of snapshot lifecycle management (SLM). + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get-status.html + * + * @param array{ + * 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 getStatus(array $params = []) + { + $url = '/_slm/status'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates or updates a snapshot lifecycle policy. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put-policy.html + * + * @param array{ + * policy_id: string, // (REQUIRED) The id of the snapshot lifecycle policy + * 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, // The snapshot lifecycle policy definition to register + * } $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 putLifecycle(array $params = []) + { + $this->checkRequiredParameters(['policy_id'], $params); + $url = '/_slm/policy/' . $this->encode($params['policy_id']); + $method = 'PUT'; + + $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)); + } + + + /** + * Turns on snapshot lifecycle management (SLM). + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-start.html + * + * @param array{ + * 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 start(array $params = []) + { + $url = '/_slm/start'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Turns off snapshot lifecycle management (SLM). + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-stop.html + * + * @param array{ + * 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 stop(array $params = []) + { + $url = '/_slm/stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Snapshot.php b/Elastic/Elasticsearch/Endpoints/Snapshot.php new file mode 100644 index 0000000..f2732da --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Snapshot.php @@ -0,0 +1,514 @@ +checkRequiredParameters(['repository'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/_cleanup'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['master_timeout','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Clones indices from one snapshot into another snapshot in the same repository. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * snapshot: string, // (REQUIRED) The name of the snapshot to clone from + * target_snapshot: string, // (REQUIRED) The name of the cloned snapshot to create + * master_timeout: time, // Explicit operation timeout for connection to master node + * 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 snapshot clone definition + * } $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 clone(array $params = []) + { + $this->checkRequiredParameters(['repository','snapshot','target_snapshot','body'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']) . '/_clone/' . $this->encode($params['target_snapshot']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['master_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)); + } + + + /** + * Creates a snapshot in a repository. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * snapshot: string, // (REQUIRED) A snapshot name + * master_timeout: time, // Explicit operation timeout for connection to master node + * wait_for_completion: boolean, // Should this request wait until the operation has completed before returning + * 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, // The snapshot definition + * } $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 create(array $params = []) + { + $this->checkRequiredParameters(['repository','snapshot'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['master_timeout','wait_for_completion','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)); + } + + + /** + * Creates a repository. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * verify: boolean, // Whether to verify the repository after creation + * 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 repository definition + * } $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 createRepository(array $params = []) + { + $this->checkRequiredParameters(['repository','body'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['master_timeout','timeout','verify','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)); + } + + + /** + * Deletes one or more snapshots. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * snapshot: list, // (REQUIRED) A comma-separated list of snapshot names + * master_timeout: time, // Explicit operation timeout for connection to master node + * 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 delete(array $params = []) + { + $this->checkRequiredParameters(['repository','snapshot'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes a repository. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: list, // (REQUIRED) Name of the snapshot repository to unregister. Wildcard (`*`) patterns are supported. + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * 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 deleteRepository(array $params = []) + { + $this->checkRequiredParameters(['repository'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['master_timeout','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about a snapshot. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * snapshot: list, // (REQUIRED) A comma-separated list of snapshot names + * master_timeout: time, // Explicit operation timeout for connection to master node + * ignore_unavailable: boolean, // Whether to ignore unavailable snapshots, defaults to false which means a SnapshotMissingException is thrown + * index_names: boolean, // Whether to include the name of each index in the snapshot. Defaults to true. + * index_details: boolean, // Whether to include details of each index in the snapshot, if those details are available. Defaults to false. + * include_repository: boolean, // Whether to include the repository name in the snapshot info. Defaults to true. + * sort: enum, // Allows setting a sort order for the result. Defaults to start_time + * size: integer, // Maximum number of snapshots to return. Defaults to 0 which means return all that match without limit. + * order: enum, // Sort order + * from_sort_value: string, // Value of the current sort column at which to start retrieval. + * after: string, // Offset identifier to start pagination from as returned by the 'next' field in the response body. + * offset: integer, // Numeric offset to start pagination based on the snapshots matching the request. Defaults to 0 + * slm_policy_filter: string, // Filter snapshots by a comma-separated list of SLM policy names that snapshots belong to. Accepts wildcards. Use the special pattern '_none' to match snapshots without an SLM policy + * verbose: boolean, // Whether to show verbose snapshot info or only show the basic info found in the repository index blob + * 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 get(array $params = []) + { + $this->checkRequiredParameters(['repository','snapshot'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['master_timeout','ignore_unavailable','index_names','index_details','include_repository','sort','size','order','from_sort_value','after','offset','slm_policy_filter','verbose','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about a repository. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: list, // A comma-separated list of repository names + * master_timeout: time, // Explicit operation timeout for connection to master node + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * 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 getRepository(array $params = []) + { + if (isset($params['repository'])) { + $url = '/_snapshot/' . $this->encode($params['repository']); + $method = 'GET'; + } else { + $url = '/_snapshot'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['master_timeout','local','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Analyzes a repository for correctness and performance + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * blob_count: number, // Number of blobs to create during the test. Defaults to 100. + * concurrency: number, // Number of operations to run concurrently during the test. Defaults to 10. + * read_node_count: number, // Number of nodes on which to read a blob after writing. Defaults to 10. + * early_read_node_count: number, // Number of nodes on which to perform an early read on a blob, i.e. before writing has completed. Early reads are rare actions so the 'rare_action_probability' parameter is also relevant. Defaults to 2. + * seed: number, // Seed for the random number generator used to create the test workload. Defaults to a random value. + * rare_action_probability: number, // Probability of taking a rare action such as an early read or an overwrite. Defaults to 0.02. + * max_blob_size: string, // Maximum size of a blob to create during the test, e.g '1gb' or '100mb'. Defaults to '10mb'. + * max_total_data_size: string, // Maximum total size of all blobs to create during the test, e.g '1tb' or '100gb'. Defaults to '1gb'. + * timeout: time, // Explicit operation timeout. Defaults to '30s'. + * detailed: boolean, // Whether to return detailed results or a summary. Defaults to 'false' so that only the summary is returned. + * rarely_abort_writes: boolean, // Whether to rarely abort writes before they complete. Defaults to 'true'. + * 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 repositoryAnalyze(array $params = []) + { + $this->checkRequiredParameters(['repository'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/_analyze'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['blob_count','concurrency','read_node_count','early_read_node_count','seed','rare_action_probability','max_blob_size','max_total_data_size','timeout','detailed','rarely_abort_writes','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Restores a snapshot. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * snapshot: string, // (REQUIRED) A snapshot name + * master_timeout: time, // Explicit operation timeout for connection to master node + * wait_for_completion: boolean, // Should this request wait until the operation has completed before returning + * 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, // Details of what to restore + * } $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 restore(array $params = []) + { + $this->checkRequiredParameters(['repository','snapshot'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']) . '/_restore'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['master_timeout','wait_for_completion','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)); + } + + + /** + * Returns information about the status of a snapshot. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // A repository name + * snapshot: list, // A comma-separated list of snapshot names + * master_timeout: time, // Explicit operation timeout for connection to master node + * ignore_unavailable: boolean, // Whether to ignore unavailable snapshots, defaults to false which means a SnapshotMissingException is thrown + * 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 status(array $params = []) + { + if (isset($params['repository']) && isset($params['snapshot'])) { + $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']) . '/_status'; + $method = 'GET'; + } elseif (isset($params['repository'])) { + $url = '/_snapshot/' . $this->encode($params['repository']) . '/_status'; + $method = 'GET'; + } else { + $url = '/_snapshot/_status'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['master_timeout','ignore_unavailable','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Verifies a repository. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + * + * @param array{ + * repository: string, // (REQUIRED) A repository name + * master_timeout: time, // Explicit operation timeout for connection to master node + * timeout: time, // Explicit operation timeout + * 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 verifyRepository(array $params = []) + { + $this->checkRequiredParameters(['repository'], $params); + $url = '/_snapshot/' . $this->encode($params['repository']) . '/_verify'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['master_timeout','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Sql.php b/Elastic/Elasticsearch/Endpoints/Sql.php new file mode 100644 index 0000000..9be51a8 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Sql.php @@ -0,0 +1,244 @@ +checkRequiredParameters(['body'], $params); + $url = '/_sql/close'; + $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)); + } + + + /** + * Deletes an async SQL search or a stored synchronous SQL search. If the search is still running, the API cancels it. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-async-sql-search-api.html + * + * @param array{ + * id: string, // (REQUIRED) The async search ID + * 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 deleteAsync(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_sql/async/delete/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the current status and available results for an async SQL search or stored synchronous SQL search + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-api.html + * + * @param array{ + * id: string, // (REQUIRED) The async search ID + * delimiter: string, // Separator for CSV results + * format: string, // Short version of the Accept header, e.g. json, yaml + * keep_alive: time, // Retention period for the search and its results + * wait_for_completion_timeout: time, // Duration to wait for complete results + * 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 getAsync(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_sql/async/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['delimiter','format','keep_alive','wait_for_completion_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the current status of an async SQL search or a stored synchronous SQL search + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/get-async-sql-search-status-api.html + * + * @param array{ + * id: string, // (REQUIRED) The async search ID + * 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 getAsyncStatus(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_sql/async/status/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Executes a SQL request + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-search-api.html + * + * @param array{ + * format: string, // a short version of the Accept header, e.g. json, yaml + * 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) Use the `query` element to start a query. Use the `cursor` element to continue a query. + * } $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 query(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_sql'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['format','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)); + } + + + /** + * Translates SQL into Elasticsearch queries + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-translate-api.html + * + * @param array{ + * 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) Specify the query in the `query` element. + * } $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 translate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_sql/translate'; + $method = empty($params['body']) ? 'GET' : '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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Ssl.php b/Elastic/Elasticsearch/Endpoints/Ssl.php new file mode 100644 index 0000000..5de7475 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Ssl.php @@ -0,0 +1,61 @@ +addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Tasks.php b/Elastic/Elasticsearch/Endpoints/Tasks.php new file mode 100644 index 0000000..6097bdc --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Tasks.php @@ -0,0 +1,149 @@ +encode($params['task_id']) . '/_cancel'; + $method = 'POST'; + } else { + $url = '/_tasks/_cancel'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['nodes','actions','parent_task_id','wait_for_completion','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about a task. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * task_id: string, // (REQUIRED) Return the task with specified id (node_id:task_number) + * wait_for_completion: boolean, // Wait for the matching tasks to complete (default: false) + * timeout: time, // Explicit operation timeout + * 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 get(array $params = []) + { + $this->checkRequiredParameters(['task_id'], $params); + $url = '/_tasks/' . $this->encode($params['task_id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['wait_for_completion','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a list of tasks. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * nodes: list, // A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * actions: list, // A comma-separated list of actions that should be returned. Leave empty to return all. + * detailed: boolean, // Return detailed task information (default: false) + * parent_task_id: string, // Return tasks with specified parent task id (node_id:task_number). Set to -1 to return all. + * wait_for_completion: boolean, // Wait for the matching tasks to complete (default: false) + * group_by: enum, // Group tasks by nodes or parent/child relationships + * timeout: time, // Explicit operation timeout + * 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 list(array $params = []) + { + $url = '/_tasks'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['nodes','actions','detailed','parent_task_id','wait_for_completion','group_by','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/TextStructure.php b/Elastic/Elasticsearch/Endpoints/TextStructure.php new file mode 100644 index 0000000..db65e57 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/TextStructure.php @@ -0,0 +1,79 @@ +checkRequiredParameters(['body'], $params); + $url = '/_text_structure/find_structure'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['lines_to_sample','line_merge_size_limit','timeout','charset','format','has_header_row','column_names','delimiter','quote','should_trim_fields','grok_pattern','ecs_compatibility','timestamp_field','timestamp_format','explain','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/x-ndjson', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Transform.php b/Elastic/Elasticsearch/Endpoints/Transform.php new file mode 100644 index 0000000..1e473f7 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Transform.php @@ -0,0 +1,411 @@ +checkRequiredParameters(['transform_id'], $params); + $url = '/_transform/' . $this->encode($params['transform_id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['force','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves configuration information for transforms. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform.html + * + * @param array{ + * transform_id: string, // The id or comma delimited list of id expressions of the transforms to get, '_all' or '*' implies get all transforms + * from: int, // skips a number of transform configs, defaults to 0 + * size: int, // specifies a max number of transforms to get, defaults to 100 + * 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) + * exclude_generated: boolean, // Omits fields that are illegal to set on transform PUT + * 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 getTransform(array $params = []) + { + if (isset($params['transform_id'])) { + $url = '/_transform/' . $this->encode($params['transform_id']); + $method = 'GET'; + } else { + $url = '/_transform'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['from','size','allow_no_match','exclude_generated','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves usage information for transforms. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform-stats.html + * + * @param array{ + * 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 + * 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) + * 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 getTransformStats(array $params = []) + { + $this->checkRequiredParameters(['transform_id'], $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']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Previews a transform. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/preview-transform.html + * + * @param array{ + * transform_id: string, // The id of the transform to preview. + * timeout: time, // Controls the time to wait for the preview + * 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, // The definition for the transform to preview + * } $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 previewTransform(array $params = []) + { + if (isset($params['transform_id'])) { + $url = '/_transform/' . $this->encode($params['transform_id']) . '/_preview'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_transform/_preview'; + $method = empty($params['body']) ? 'GET' : '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)); + } + + + /** + * Instantiates a transform. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html + * + * @param array{ + * transform_id: string, // (REQUIRED) The id of the new transform. + * defer_validation: boolean, // If validations should be deferred until transform starts, defaults to false. + * 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) + * 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 transform definition + * } $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 putTransform(array $params = []) + { + $this->checkRequiredParameters(['transform_id','body'], $params); + $url = '/_transform/' . $this->encode($params['transform_id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['defer_validation','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)); + } + + + /** + * Resets an existing transform. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/reset-transform.html + * + * @param array{ + * transform_id: string, // (REQUIRED) The id of the transform to reset + * force: boolean, // When `true`, the transform is reset regardless of its current state. The default value is `false`, meaning that the transform must be `stopped` before it can be reset. + * timeout: time, // Controls the time to wait for the transform to reset + * 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 resetTransform(array $params = []) + { + $this->checkRequiredParameters(['transform_id'], $params); + $url = '/_transform/' . $this->encode($params['transform_id']) . '/_reset'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['force','timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Starts one or more transforms. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/start-transform.html + * + * @param array{ + * transform_id: string, // (REQUIRED) The id of the transform to start + * 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) + * 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 startTransform(array $params = []) + { + $this->checkRequiredParameters(['transform_id'], $params); + $url = '/_transform/' . $this->encode($params['transform_id']) . '/_start'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Stops one or more transforms. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-transform.html + * + * @param array{ + * transform_id: string, // (REQUIRED) The id of the transform to stop + * force: boolean, // Whether to force stop a failed transform or not. Default to false + * wait_for_completion: boolean, // Whether to wait for the transform to fully stop before returning or not. Default to false + * timeout: time, // Controls the time to wait until the transform has stopped. Default to 30 seconds + * 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) + * wait_for_checkpoint: boolean, // Whether to wait for the transform to reach a checkpoint before stopping. Default to false + * 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 stopTransform(array $params = []) + { + $this->checkRequiredParameters(['transform_id'], $params); + $url = '/_transform/' . $this->encode($params['transform_id']) . '/_stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['force','wait_for_completion','timeout','allow_no_match','wait_for_checkpoint','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Updates certain properties of a transform. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/update-transform.html + * + * @param array{ + * transform_id: string, // (REQUIRED) The id of the transform. + * defer_validation: boolean, // If validations should be deferred until transform starts, defaults to false. + * timeout: time, // Controls the time to wait for the update + * 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 update transform definition + * } $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 updateTransform(array $params = []) + { + $this->checkRequiredParameters(['transform_id','body'], $params); + $url = '/_transform/' . $this->encode($params['transform_id']) . '/_update'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['defer_validation','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)); + } + + + /** + * Upgrades all transforms. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/upgrade-transforms.html + * + * @param array{ + * dry_run: boolean, // Whether to only check for updates but don't execute + * timeout: time, // Controls the time to wait for the upgrade + * 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 upgradeTransforms(array $params = []) + { + $url = '/_transform/_upgrade'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['dry_run','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)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Watcher.php b/Elastic/Elasticsearch/Endpoints/Watcher.php new file mode 100644 index 0000000..c1dafe5 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Watcher.php @@ -0,0 +1,426 @@ +checkRequiredParameters(['watch_id'], $params); + if (isset($params['action_id'])) { + $url = '/_watcher/watch/' . $this->encode($params['watch_id']) . '/_ack/' . $this->encode($params['action_id']); + $method = 'PUT'; + } else { + $url = '/_watcher/watch/' . $this->encode($params['watch_id']) . '/_ack'; + $method = 'PUT'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Activates a currently inactive watch. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-activate-watch.html + * + * @param array{ + * watch_id: string, // (REQUIRED) Watch ID + * 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 activateWatch(array $params = []) + { + $this->checkRequiredParameters(['watch_id'], $params); + $url = '/_watcher/watch/' . $this->encode($params['watch_id']) . '/_activate'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deactivates a currently active watch. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-deactivate-watch.html + * + * @param array{ + * watch_id: string, // (REQUIRED) Watch ID + * 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 deactivateWatch(array $params = []) + { + $this->checkRequiredParameters(['watch_id'], $params); + $url = '/_watcher/watch/' . $this->encode($params['watch_id']) . '/_deactivate'; + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Removes a watch from Watcher. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-delete-watch.html + * + * @param array{ + * id: string, // (REQUIRED) Watch ID + * 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 deleteWatch(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_watcher/watch/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Forces the execution of a stored watch. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-execute-watch.html + * + * @param array{ + * id: string, // Watch ID + * debug: boolean, // indicates whether the watch should execute in debug mode + * 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, // Execution control + * } $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 executeWatch(array $params = []) + { + if (isset($params['id'])) { + $url = '/_watcher/watch/' . $this->encode($params['id']) . '/_execute'; + $method = 'PUT'; + } else { + $url = '/_watcher/watch/_execute'; + $method = 'PUT'; + } + $url = $this->addQueryString($url, $params, ['debug','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)); + } + + + /** + * Retrieves a watch by its ID. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-get-watch.html + * + * @param array{ + * id: string, // (REQUIRED) Watch ID + * 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 getWatch(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_watcher/watch/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a new watch, or updates an existing one. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-put-watch.html + * + * @param array{ + * id: string, // (REQUIRED) Watch ID + * active: boolean, // Specify whether the watch is in/active by default + * version: number, // Explicit version number for concurrency control + * if_seq_no: number, // only update the watch if the last operation that has changed the watch has the specified sequence number + * if_primary_term: number, // only update the watch if the last operation that has changed the watch has the specified primary term + * 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, // The watch + * } $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 putWatch(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_watcher/watch/' . $this->encode($params['id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['active','version','if_seq_no','if_primary_term','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)); + } + + + /** + * Retrieves stored watches. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-query-watches.html + * + * @param array{ + * 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, // From, size, query, sort and search_after + * } $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 queryWatches(array $params = []) + { + $url = '/_watcher/_query/watches'; + $method = empty($params['body']) ? 'GET' : '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)); + } + + + /** + * Starts Watcher if it is not already running. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-start.html + * + * @param array{ + * 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 start(array $params = []) + { + $url = '/_watcher/_start'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves the current Watcher metrics. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stats.html + * + * @param array{ + * metric: list, // Controls what additional stat metrics should be include in the response + * emit_stacktraces: boolean, // Emits stack traces of currently running watches + * 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 stats(array $params = []) + { + if (isset($params['metric'])) { + $url = '/_watcher/stats/' . $this->encode($params['metric']); + $method = 'GET'; + } else { + $url = '/_watcher/stats'; + $method = 'GET'; + } + $url = $this->addQueryString($url, $params, ['emit_stacktraces','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Stops Watcher if it is running. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stop.html + * + * @param array{ + * 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 stop(array $params = []) + { + $url = '/_watcher/_stop'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Endpoints/Xpack.php b/Elastic/Elasticsearch/Endpoints/Xpack.php new file mode 100644 index 0000000..7095ad6 --- /dev/null +++ b/Elastic/Elasticsearch/Endpoints/Xpack.php @@ -0,0 +1,96 @@ +addQueryString($url, $params, ['categories','accept_enterprise','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Retrieves usage information about the installed X-Pack features. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/usage-api.html + * + * @param array{ + * master_timeout: time, // Specify timeout for watch write operation + * 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 usage(array $params = []) + { + $url = '/_xpack/usage'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Exception/ArrayAccessException.php b/Elastic/Elasticsearch/Exception/ArrayAccessException.php new file mode 100644 index 0000000..831b9c4 --- /dev/null +++ b/Elastic/Elasticsearch/Exception/ArrayAccessException.php @@ -0,0 +1,22 @@ +productCheck($response); + $this->response = $response; + $status = $response->getStatusCode(); + if ($throwException && $status > 399 && $status < 500) { + $error = new ClientResponseException( + sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), + $status + ); + throw $error->setResponse($response); + } elseif ($throwException && $status > 499 && $status < 600) { + $error = new ServerResponseException( + sprintf("%s %s: %s", $status, $response->getReasonPhrase(), (string) $response->getBody()), + $status + ); + throw $error->setResponse($response); + } + } + + /** + * Return true if status code is 2xx + */ + public function asBool(): bool + { + return $this->response->getStatusCode() >=200 && $this->response->getStatusCode() < 300; + } + + /** + * Converts the body content to array, if possible. + * Otherwise, it throws an UnknownContentTypeException + * if Content-Type is not specified or unknown. + * + * @throws UnknownContentTypeException + */ + public function asArray(): array + { + if (isset($this->asArray)) { + return $this->asArray; + } + if (!$this->response->hasHeader('Content-Type')) { + throw new UnknownContentTypeException('No Content-Type specified in the response'); + } + $contentType = $this->response->getHeaderLine('Content-Type'); + if (strpos($contentType, 'application/json') !== false || + strpos($contentType, 'application/vnd.elasticsearch+json') !== false) { + $this->asArray = JsonSerializer::unserialize($this->asString()); + return $this->asArray; + } + if (strpos($contentType, 'application/x-ndjson') !== false || + strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== false) { + $this->asArray = NDJsonSerializer::unserialize($this->asString()); + return $this->asArray; + } + if (strpos($contentType, 'text/csv') !== false) { + $this->asArray = CsvSerializer::unserialize($this->asString()); + return $this->asArray; + } + throw new UnknownContentTypeException(sprintf( + "Cannot deserialize the reponse as array with Content-Type: %s", + $contentType + )); + } + + /** + * Converts the body content to object, if possible. + * Otherwise, it throws an UnknownContentTypeException + * if Content-Type is not specified or unknown. + * + * @throws UnknownContentTypeException + */ + public function asObject(): object + { + if (isset($this->asObject)) { + return $this->asObject; + } + $contentType = $this->response->getHeaderLine('Content-Type'); + if (strpos($contentType, 'application/json') !== false || + strpos($contentType, 'application/vnd.elasticsearch+json') !== false) { + $this->asObject = JsonSerializer::unserialize($this->asString(), ['type' => 'object']); + return $this->asObject; + } + if (strpos($contentType, 'application/x-ndjson') !== false || + strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== false) { + $this->asObject = NDJsonSerializer::unserialize($this->asString(), ['type' => 'object']); + return $this->asObject; + } + if (strpos($contentType, 'text/xml') !== false || strpos($contentType, 'application/xml') !== false) { + $this->asObject = XmlSerializer::unserialize($this->asString()); + return $this->asObject; + } + throw new UnknownContentTypeException(sprintf( + "Cannot deserialize the reponse as object with Content-Type: %s", + $contentType + )); + } + + /** + * Converts the body content to string + */ + public function asString(): string + { + if (empty($this->asString)) { + $this->asString = (string) $this->response->getBody(); + } + return $this->asString; + } + + /** + * Converts the body content to string + */ + public function __toString(): string + { + return $this->asString(); + } + + /** + * Access the body content as object properties + * + * @see https://www.php.net/manual/en/language.oop5.overloading.php#object.get + */ + public function __get($name) + { + return $this->asObject()->$name ?? null; + } + + /** + * ArrayAccess interface + * + * @see https://www.php.net/manual/en/class.arrayaccess.php + */ + public function offsetExists($offset): bool + { + return isset($this->asArray()[$offset]); + } + + /** + * ArrayAccess interface + * + * @see https://www.php.net/manual/en/class.arrayaccess.php + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->asArray()[$offset]; + } + + /** + * ArrayAccess interface + * + * @see https://www.php.net/manual/en/class.arrayaccess.php + */ + public function offsetSet($offset, $value): void + { + throw new ArrayAccessException('The array is reading only'); + } + + /** + * ArrayAccess interface + * + * @see https://www.php.net/manual/en/class.arrayaccess.php + */ + public function offsetUnset($offset): void + { + throw new ArrayAccessException('The array is reading only'); + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Response/ElasticsearchInterface.php b/Elastic/Elasticsearch/Response/ElasticsearchInterface.php new file mode 100644 index 0000000..c2f3755 --- /dev/null +++ b/Elastic/Elasticsearch/Response/ElasticsearchInterface.php @@ -0,0 +1,25 @@ +checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_bulk'; + $method = 'POST'; + } else { + $url = '/_bulk'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['wait_for_active_shards','refresh','routing','timeout','type','_source','_source_excludes','_source_includes','pipeline','require_alias','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/x-ndjson', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Explicitly clears the search context for a scroll. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/clear-scroll-api.html + * + * @param array{ + * scroll_id: list, // A comma-separated list of scroll IDs to clear + * 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, // A comma-separated list of scroll IDs to clear if none was specified via the scroll_id parameter + * } $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 clearScroll(array $params = []) + { + if (isset($params['scroll_id'])) { + $url = '/_search/scroll/' . $this->encode($params['scroll_id']); + $method = 'DELETE'; + } else { + $url = '/_search/scroll'; + $method = 'DELETE'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Close a point in time + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + * + * @param array{ + * 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, // a point-in-time id to close + * } $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 closePointInTime(array $params = []) + { + $url = '/_pit'; + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns number of documents matching a query. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html + * + * @param array{ + * index: list, // A comma-separated list of indices to restrict the results + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * ignore_throttled: boolean, // Whether specified concrete, expanded or aliased indices should be ignored when throttled + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * min_score: number, // Include only documents with a specific `_score` value in the result + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * routing: list, // A comma-separated list of specific routing values + * q: string, // Query in the Lucene query string syntax + * analyzer: string, // The analyzer to use for the query string + * analyze_wildcard: boolean, // Specify whether wildcard and prefix queries should be analyzed (default: false) + * default_operator: enum, // The default operator for query string query (AND or OR) + * df: string, // The field to use as default where no field prefix is given in the query string + * lenient: boolean, // Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * terminate_after: number, // The maximum count for each shard, upon reaching which the query execution will terminate early + * 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, // A query to restrict the results specified with the Query DSL (optional) + * } $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 count(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_count'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_count'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','ignore_throttled','allow_no_indices','expand_wildcards','min_score','preference','routing','q','analyzer','analyze_wildcard','default_operator','df','lenient','terminate_after','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Creates a new document in the index. + * + * Returns a 409 response when a document with a same ID already exists in the index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + * + * @param array{ + * id: string, // (REQUIRED) Document ID + * index: string, // (REQUIRED) The name of the index + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes. + * routing: string, // Specific routing value + * timeout: time, // Explicit operation timeout + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * pipeline: string, // The pipeline id to preprocess incoming documents with + * 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 document + * } $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 create(array $params = []) + { + $this->checkRequiredParameters(['id','index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_create/' . $this->encode($params['id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['wait_for_active_shards','refresh','routing','timeout','version','version_type','pipeline','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Removes a document from the index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html + * + * @param array{ + * id: string, // (REQUIRED) The document ID + * index: string, // (REQUIRED) The name of the index + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before proceeding with the delete operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes. + * routing: string, // Specific routing value + * timeout: time, // Explicit operation timeout + * if_seq_no: number, // only perform the delete operation if the last operation that has changed the document has the specified sequence number + * if_primary_term: number, // only perform the delete operation if the last operation that has changed the document has the specified primary term + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * 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 delete(array $params = []) + { + $this->checkRequiredParameters(['id','index'], $params); + $url = '/' . $this->encode($params['index']) . '/_doc/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['wait_for_active_shards','refresh','routing','timeout','if_seq_no','if_primary_term','version','version_type','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes documents matching the provided query. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * analyzer: string, // The analyzer to use for the query string + * analyze_wildcard: boolean, // Specify whether wildcard and prefix queries should be analyzed (default: false) + * default_operator: enum, // The default operator for query string query (AND or OR) + * df: string, // The field to use as default where no field prefix is given in the query string + * from: number, // Starting offset (default: 0) + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * conflicts: enum, // What to do when the delete by query hits version conflicts? + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * lenient: boolean, // Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * q: string, // Query in the Lucene query string syntax + * routing: list, // A comma-separated list of specific routing values + * scroll: time, // Specify how long a consistent view of the index should be maintained for scrolled search + * search_type: enum, // Search operation type + * search_timeout: time, // Explicit timeout for each search request. Defaults to no timeout. + * max_docs: number, // Maximum number of documents to process (default: all documents) + * sort: list, // A comma-separated list of : pairs + * terminate_after: number, // The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * stats: list, // Specific 'tag' of the request for logging and statistical purposes + * version: boolean, // Specify whether to return document version as part of a hit + * request_cache: boolean, // Specify if request cache should be used for this request or not, defaults to index level setting + * refresh: boolean, // Should the affected indexes be refreshed? + * timeout: time, // Time each individual bulk request should wait for shards that are unavailable. + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before proceeding with the delete by query operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * scroll_size: number, // Size on the scroll request powering the delete by query + * wait_for_completion: boolean, // Should the request should block until the delete by query is complete. + * requests_per_second: number, // The throttle for this request in sub-requests per second. -1 means no throttle. + * slices: number|string, // The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks. Can be set to `auto`. + * 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 search definition using the Query DSL + * } $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 deleteByQuery(array $params = []) + { + $this->checkRequiredParameters(['index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_delete_by_query'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['analyzer','analyze_wildcard','default_operator','df','from','ignore_unavailable','allow_no_indices','conflicts','expand_wildcards','lenient','preference','q','routing','scroll','search_type','search_timeout','max_docs','sort','terminate_after','stats','version','request_cache','refresh','timeout','wait_for_active_shards','scroll_size','wait_for_completion','requests_per_second','slices','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Changes the number of requests per second for a particular Delete By Query operation. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html + * + * @param array{ + * task_id: string, // (REQUIRED) The task id to rethrottle + * requests_per_second: number, // The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. + * 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 deleteByQueryRethrottle(array $params = []) + { + $this->checkRequiredParameters(['task_id','requests_per_second'], $params); + $url = '/_delete_by_query/' . $this->encode($params['task_id']) . '/_rethrottle'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['requests_per_second','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Deletes a script. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html + * + * @param array{ + * id: string, // (REQUIRED) Script ID + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 deleteScript(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_scripts/' . $this->encode($params['id']); + $method = 'DELETE'; + + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about whether a document exists in an index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + * + * @param array{ + * id: string, // (REQUIRED) The document ID + * index: string, // (REQUIRED) The name of the index + * stored_fields: list, // A comma-separated list of stored fields to return in the response + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * realtime: boolean, // Specify whether to perform the operation in realtime or search mode + * refresh: boolean, // Refresh the shard containing the document before performing the operation + * routing: string, // Specific routing value + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * 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 exists(array $params = []) + { + $this->checkRequiredParameters(['id','index'], $params); + $url = '/' . $this->encode($params['index']) . '/_doc/' . $this->encode($params['id']); + $method = 'HEAD'; + + $url = $this->addQueryString($url, $params, ['stored_fields','preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','version','version_type','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about whether a document source exists in an index. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + * + * @param array{ + * id: string, // (REQUIRED) The document ID + * index: string, // (REQUIRED) The name of the index + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * realtime: boolean, // Specify whether to perform the operation in realtime or search mode + * refresh: boolean, // Refresh the shard containing the document before performing the operation + * routing: string, // Specific routing value + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * 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 existsSource(array $params = []) + { + $this->checkRequiredParameters(['id','index'], $params); + $url = '/' . $this->encode($params['index']) . '/_source/' . $this->encode($params['id']); + $method = 'HEAD'; + + $url = $this->addQueryString($url, $params, ['preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','version','version_type','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about why a specific matches (or doesn't match) a query. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html + * + * @param array{ + * id: string, // (REQUIRED) The document ID + * index: string, // (REQUIRED) The name of the index + * analyze_wildcard: boolean, // Specify whether wildcards and prefix queries in the query string query should be analyzed (default: false) + * analyzer: string, // The analyzer for the query string query + * default_operator: enum, // The default operator for query string query (AND or OR) + * df: string, // The default field for query string query (default: _all) + * stored_fields: list, // A comma-separated list of stored fields to return in the response + * lenient: boolean, // Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * q: string, // Query in the Lucene query string syntax + * routing: string, // Specific routing value + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * 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, // The query definition using the Query DSL + * } $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 explain(array $params = []) + { + $this->checkRequiredParameters(['id','index'], $params); + $url = '/' . $this->encode($params['index']) . '/_explain/' . $this->encode($params['id']); + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['analyze_wildcard','analyzer','default_operator','df','stored_fields','lenient','preference','q','routing','_source','_source_excludes','_source_includes','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the information about the capabilities of fields among multiple indices. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-caps.html + * + * @param array{ + * index: list, // A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices + * fields: list, // A comma-separated list of field names + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * include_unmapped: boolean, // Indicates whether unmapped fields should be included in the response. + * filters: list, // An optional set of filters: can include +metadata,-metadata,-nested,-multifield,-parent + * types: list, // Only return results for fields that have one of the types in the list + * 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, // An index filter specified with the Query DSL + * } $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 fieldCaps(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_field_caps'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_field_caps'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['fields','ignore_unavailable','allow_no_indices','expand_wildcards','include_unmapped','filters','types','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a document. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + * + * @param array{ + * id: string, // (REQUIRED) The document ID + * index: string, // (REQUIRED) The name of the index + * force_synthetic_source: boolean, // Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index. + * stored_fields: list, // A comma-separated list of stored fields to return in the response + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * realtime: boolean, // Specify whether to perform the operation in realtime or search mode + * refresh: boolean, // Refresh the shard containing the document before performing the operation + * routing: string, // Specific routing value + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * 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 get(array $params = []) + { + $this->checkRequiredParameters(['id','index'], $params); + $url = '/' . $this->encode($params['index']) . '/_doc/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['force_synthetic_source','stored_fields','preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','version','version_type','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns a script. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html + * + * @param array{ + * id: string, // (REQUIRED) Script ID + * master_timeout: time, // Specify timeout for connection to master + * 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 getScript(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_scripts/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns all script contexts. + * + * @see https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-contexts.html + * + * @param array{ + * 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 getScriptContext(array $params = []) + { + $url = '/_script_context'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns available script types, languages and contexts + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html + * + * @param array{ + * 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 getScriptLanguages(array $params = []) + { + $url = '/_script_language'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns the source of a document. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + * + * @param array{ + * id: string, // (REQUIRED) The document ID + * index: string, // (REQUIRED) The name of the index + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * realtime: boolean, // Specify whether to perform the operation in realtime or search mode + * refresh: boolean, // Refresh the shard containing the document before performing the operation + * routing: string, // Specific routing value + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * 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 getSource(array $params = []) + { + $this->checkRequiredParameters(['id','index'], $params); + $url = '/' . $this->encode($params['index']) . '/_source/' . $this->encode($params['id']); + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','version','version_type','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. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + * + * @param array{ + * id: string, // Document ID + * index: string, // (REQUIRED) The name of the index + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * op_type: enum, // Explicit operation type. Defaults to `index` for requests with an explicit document ID, and to `create`for requests without an explicit document ID + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes. + * routing: string, // Specific routing value + * timeout: time, // Explicit operation timeout + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * if_seq_no: number, // only perform the index operation if the last operation that has changed the document has the specified sequence number + * if_primary_term: number, // only perform the index operation if the last operation that has changed the document has the specified primary term + * pipeline: string, // The pipeline id to preprocess incoming documents with + * require_alias: boolean, // When true, requires destination to be an alias. Default is false + * 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 document + * } $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 index(array $params = []) + { + $this->checkRequiredParameters(['index','body'], $params); + if (isset($params['id'])) { + $url = '/' . $this->encode($params['index']) . '/_doc/' . $this->encode($params['id']); + $method = 'PUT'; + } else { + $url = '/' . $this->encode($params['index']) . '/_doc'; + $method = 'POST'; + } + $url = $this->addQueryString($url, $params, ['wait_for_active_shards','op_type','refresh','routing','timeout','version','version_type','if_seq_no','if_primary_term','pipeline','require_alias','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns basic information about the cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html + * + * @param array{ + * 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 info(array $params = []) + { + $url = '/'; + $method = 'GET'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Performs a kNN search. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names to search; use `_all` to perform the operation on all indices + * routing: list, // A comma-separated list of specific routing values + * 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, // The search definition + * } $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 knnSearch(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_knn_search'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['routing','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to get multiple documents in one request. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html + * + * @param array{ + * index: string, // The name of the index + * force_synthetic_source: boolean, // Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index. + * stored_fields: list, // A comma-separated list of stored fields to return in the response + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * realtime: boolean, // Specify whether to perform the operation in realtime or search mode + * refresh: boolean, // Refresh the shard containing the document before performing the operation + * routing: string, // Specific routing value + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * 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) Document identifiers; can be either `docs` (containing full document information) or `ids` (when index is provided in the URL. + * } $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 mget(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_mget'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_mget'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['force_synthetic_source','stored_fields','preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to execute several search operations in one request. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html + * + * @param array{ + * index: list, // A comma-separated list of index names to use as default + * search_type: enum, // Search operation type + * max_concurrent_searches: number, // Controls the maximum number of concurrent searches the multi search api will execute + * typed_keys: boolean, // Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * pre_filter_shard_size: number, // A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. + * max_concurrent_shard_requests: number, // The number of concurrent shard requests each sub search executes concurrently per node. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests + * rest_total_hits_as_int: boolean, // Indicates whether hits.total should be rendered as an integer or an object in the rest search response + * ccs_minimize_roundtrips: boolean, // Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution + * 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 request definitions (metadata-search request definition pairs), separated by newlines + * } $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 msearch(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_msearch'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_msearch'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['search_type','max_concurrent_searches','typed_keys','pre_filter_shard_size','max_concurrent_shard_requests','rest_total_hits_as_int','ccs_minimize_roundtrips','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/x-ndjson', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to execute several search template operations in one request. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html + * + * @param array{ + * index: list, // A comma-separated list of index names to use as default + * search_type: enum, // Search operation type + * typed_keys: boolean, // Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * max_concurrent_searches: number, // Controls the maximum number of concurrent searches the multi search api will execute + * rest_total_hits_as_int: boolean, // Indicates whether hits.total should be rendered as an integer or an object in the rest search response + * ccs_minimize_roundtrips: boolean, // Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution + * 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 request definitions (metadata-search request definition pairs), separated by newlines + * } $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 msearchTemplate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_msearch/template'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_msearch/template'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['search_type','typed_keys','max_concurrent_searches','rest_total_hits_as_int','ccs_minimize_roundtrips','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/x-ndjson', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns multiple termvectors in one request. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html + * + * @param array{ + * index: string, // The index in which the document resides. + * ids: list, // A comma-separated list of documents ids. You must define ids as parameter or set "ids" or "docs" in the request body + * term_statistics: boolean, // Specifies if total term frequency and document frequency should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * field_statistics: boolean, // Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * fields: list, // A comma-separated list of fields to return. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * offsets: boolean, // Specifies if term offsets should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * positions: boolean, // Specifies if term positions should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * payloads: boolean, // Specifies if term payloads should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * preference: string, // Specify the node or shard the operation should be performed on (default: random) .Applies to all returned documents unless otherwise specified in body "params" or "docs". + * routing: string, // Specific routing value. Applies to all returned documents unless otherwise specified in body "params" or "docs". + * realtime: boolean, // Specifies if requests are real-time as opposed to near-real-time (default: true). + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * 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, // Define ids, documents, parameters or a list of parameters per document here. You must at least provide a list of document ids. See documentation. + * } $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 mtermvectors(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_mtermvectors'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_mtermvectors'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['ids','term_statistics','field_statistics','fields','offsets','positions','payloads','preference','routing','realtime','version','version_type','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Open a point in time that can be used in subsequent searches + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/point-in-time-api.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names to open point in time; use `_all` or empty string to perform the operation on all indices + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * routing: string, // Specific routing value + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * keep_alive: string, // Specific the time to live for the point in time + * 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 openPointInTime(array $params = []) + { + $this->checkRequiredParameters(['index','keep_alive'], $params); + $url = '/' . $this->encode($params['index']) . '/_pit'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['preference','routing','ignore_unavailable','expand_wildcards','keep_alive','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns whether the cluster is running. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html + * + * @param array{ + * 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 ping(array $params = []) + { + $url = '/'; + $method = 'HEAD'; + + $url = $this->addQueryString($url, $params, ['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 script. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html + * + * @param array{ + * id: string, // (REQUIRED) Script ID + * context: string, // Script context + * timeout: time, // Explicit operation timeout + * master_timeout: time, // Specify timeout for connection to master + * 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 document + * } $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 putScript(array $params = []) + { + $this->checkRequiredParameters(['id','body'], $params); + if (isset($params['context'])) { + $url = '/_scripts/' . $this->encode($params['id']) . '/' . $this->encode($params['context']); + $method = 'PUT'; + } else { + $url = '/_scripts/' . $this->encode($params['id']); + $method = 'PUT'; + } + $url = $this->addQueryString($url, $params, ['timeout','master_timeout','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to evaluate the quality of ranked search results over a set of typical search queries + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-rank-eval.html + * + * @param array{ + * index: list, // A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * search_type: enum, // Search operation type + * 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 ranking evaluation search definition, including search requests, document ratings and ranking metric definition. + * } $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 rankEval(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_rank_eval'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_rank_eval'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','allow_no_indices','expand_wildcards','search_type','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to copy documents from one index to another, optionally filtering the source + * documents by a query, changing the destination index settings, or fetching the + * documents from a remote cluster. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html + * + * @param array{ + * refresh: boolean, // Should the affected indexes be refreshed? + * timeout: time, // Time each individual bulk request should wait for shards that are unavailable. + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before proceeding with the reindex operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * wait_for_completion: boolean, // Should the request should block until the reindex is complete. + * requests_per_second: number, // The throttle to set on this request in sub-requests per second. -1 means no throttle. + * scroll: time, // Control how long to keep the search context alive + * slices: number|string, // The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks. Can be set to `auto`. + * max_docs: number, // Maximum number of documents to process (default: all documents) + * 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 search definition using the Query DSL and the prototype for the index request. + * } $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 reindex(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + $url = '/_reindex'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['refresh','timeout','wait_for_active_shards','wait_for_completion','requests_per_second','scroll','slices','max_docs','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Changes the number of requests per second for a particular Reindex operation. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html + * + * @param array{ + * task_id: string, // (REQUIRED) The task id to rethrottle + * requests_per_second: number, // The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. + * 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 reindexRethrottle(array $params = []) + { + $this->checkRequiredParameters(['task_id','requests_per_second'], $params); + $url = '/_reindex/' . $this->encode($params['task_id']) . '/_rethrottle'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['requests_per_second','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to use the Mustache language to pre-render a search definition. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/render-search-template-api.html + * + * @param array{ + * id: string, // The id of the stored search template + * 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, // The search definition template and its params + * } $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 renderSearchTemplate(array $params = []) + { + if (isset($params['id'])) { + $url = '/_render/template/' . $this->encode($params['id']); + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_render/template'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows an arbitrary script to be executed and a result to be returned + * + * @see https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * 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, // The script to execute + * } $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 scriptsPainlessExecute(array $params = []) + { + $url = '/_scripts/painless/_execute'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to retrieve a large numbers of results from a single search request. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-body.html#request-body-search-scroll + * + * @param array{ + * scroll_id: string, // The scroll ID + * scroll: time, // Specify how long a consistent view of the index should be maintained for scrolled search + * rest_total_hits_as_int: boolean, // Indicates whether hits.total should be rendered as an integer or an object in the rest search response + * 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, // The scroll ID if not passed by URL or query parameter. + * } $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 scroll(array $params = []) + { + if (isset($params['scroll_id'])) { + $url = '/_search/scroll/' . $this->encode($params['scroll_id']); + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_search/scroll'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['scroll','rest_total_hits_as_int','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns results matching a query. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html + * + * @param array{ + * index: list, // A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * analyzer: string, // The analyzer to use for the query string + * analyze_wildcard: boolean, // Specify whether wildcard and prefix queries should be analyzed (default: false) + * ccs_minimize_roundtrips: boolean, // Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution + * default_operator: enum, // The default operator for query string query (AND or OR) + * df: string, // The field to use as default where no field prefix is given in the query string + * explain: boolean, // Specify whether to return detailed information about score computation as part of a hit + * stored_fields: list, // A comma-separated list of stored fields to return as part of a hit + * docvalue_fields: list, // A comma-separated list of fields to return as the docvalue representation of a field for each hit + * from: number, // Starting offset (default: 0) + * force_synthetic_source: boolean, // Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index. + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * ignore_throttled: boolean, // Whether specified concrete, expanded or aliased indices should be ignored when throttled + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * lenient: boolean, // Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * q: string, // Query in the Lucene query string syntax + * routing: list, // A comma-separated list of specific routing values + * scroll: time, // Specify how long a consistent view of the index should be maintained for scrolled search + * search_type: enum, // Search operation type + * size: number, // Number of hits to return (default: 10) + * sort: list, // A comma-separated list of : pairs + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * terminate_after: number, // The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * stats: list, // Specific 'tag' of the request for logging and statistical purposes + * suggest_field: string, // Specify which field to use for suggestions + * suggest_mode: enum, // Specify suggest mode + * suggest_size: number, // How many suggestions to return in response + * suggest_text: string, // The source text for which the suggestions should be returned + * timeout: time, // Explicit operation timeout + * track_scores: boolean, // Whether to calculate and return scores even if they are not used for sorting + * track_total_hits: boolean|long, // Indicate if the number of documents that match the query should be tracked. A number can also be specified, to accurately track the total hit count up to the number. + * allow_partial_search_results: boolean, // Indicate if an error should be returned if there is a partial search failure or timeout + * typed_keys: boolean, // Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * version: boolean, // Specify whether to return document version as part of a hit + * seq_no_primary_term: boolean, // Specify whether to return sequence number and primary term of the last modification of each hit + * request_cache: boolean, // Specify if request cache should be used for this request or not, defaults to index level setting + * batched_reduce_size: number, // The number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large. + * max_concurrent_shard_requests: number, // The number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests + * pre_filter_shard_size: number, // A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. + * rest_total_hits_as_int: boolean, // Indicates whether hits.total should be rendered as an integer or an object in the rest search response + * min_compatible_shard_node: string, // The minimum compatible version that all shards involved in search should have for this request to be successful + * 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, // The search definition using the Query DSL + * } $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 search(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_search'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_search'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['analyzer','analyze_wildcard','ccs_minimize_roundtrips','default_operator','df','explain','stored_fields','docvalue_fields','from','force_synthetic_source','ignore_unavailable','ignore_throttled','allow_no_indices','expand_wildcards','lenient','preference','q','routing','scroll','search_type','size','sort','_source','_source_excludes','_source_includes','terminate_after','stats','suggest_field','suggest_mode','suggest_size','suggest_text','timeout','track_scores','track_total_hits','allow_partial_search_results','typed_keys','version','seq_no_primary_term','request_cache','batched_reduce_size','max_concurrent_shard_requests','pre_filter_shard_size','rest_total_hits_as_int','min_compatible_shard_node','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Searches a vector tile for geospatial values. Returns results as a binary Mapbox vector tile. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-vector-tile-api.html + * @internal This API is EXPERIMENTAL and may be changed or removed completely in a future release + * + * @param array{ + * index: list, // (REQUIRED) Comma-separated list of data streams, indices, or aliases to search + * field: string, // (REQUIRED) Field containing geospatial data to return + * zoom: int, // (REQUIRED) Zoom level for the vector tile to search + * x: int, // (REQUIRED) X coordinate for the vector tile to search + * y: int, // (REQUIRED) Y coordinate for the vector tile to search + * exact_bounds: boolean, // If false, the meta layer's feature is the bounding box of the tile. If true, the meta layer's feature is a bounding box resulting from a `geo_bounds` aggregation. + * extent: int, // Size, in pixels, of a side of the vector tile. + * grid_precision: int, // Additional zoom levels available through the aggs layer. Accepts 0-8. + * grid_type: enum, // Determines the geometry type for features in the aggs layer. + * size: int, // Maximum number of features to return in the hits layer. Accepts 0-10000. + * track_total_hits: boolean|long, // Indicate if the number of documents that match the query should be tracked. A number can also be specified, to accurately track the total hit count up to the number. + * with_labels: boolean, // If true, the hits and aggs layers will contain additional point features with suggested label positions for the original features. + * 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, // Search request body. + * } $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 searchMvt(array $params = []) + { + $this->checkRequiredParameters(['index','field','zoom','x','y'], $params); + $url = '/' . $this->encode($params['index']) . '/_mvt/' . $this->encode($params['field']) . '/' . $this->encode($params['zoom']) . '/' . $this->encode($params['x']) . '/' . $this->encode($params['y']); + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['exact_bounds','extent','grid_precision','grid_type','size','track_total_hits','with_labels','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/vnd.mapbox-vector-tile', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information about the indices and shards that a search request would be executed against. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html + * + * @param array{ + * index: list, // A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * routing: string, // Specific routing value + * local: boolean, // Return local information, do not retrieve the state from master node (default: false) + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * 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 searchShards(array $params = []) + { + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_search_shards'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_search_shards'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['preference','routing','local','ignore_unavailable','allow_no_indices','expand_wildcards','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Allows to use the Mustache language to pre-render a search definition. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html + * + * @param array{ + * index: list, // A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * ignore_throttled: boolean, // Whether specified concrete, expanded or aliased indices should be ignored when throttled + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * routing: list, // A comma-separated list of specific routing values + * scroll: time, // Specify how long a consistent view of the index should be maintained for scrolled search + * search_type: enum, // Search operation type + * explain: boolean, // Specify whether to return detailed information about score computation as part of a hit + * profile: boolean, // Specify whether to profile the query execution + * typed_keys: boolean, // Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * rest_total_hits_as_int: boolean, // Indicates whether hits.total should be rendered as an integer or an object in the rest search response + * ccs_minimize_roundtrips: boolean, // Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution + * 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 search definition template and its params + * } $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 searchTemplate(array $params = []) + { + $this->checkRequiredParameters(['body'], $params); + if (isset($params['index'])) { + $url = '/' . $this->encode($params['index']) . '/_search/template'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/_search/template'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['ignore_unavailable','ignore_throttled','allow_no_indices','expand_wildcards','preference','routing','scroll','search_type','explain','profile','typed_keys','rest_total_hits_as_int','ccs_minimize_roundtrips','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * The terms enum API can be used to discover terms in the index that begin with the provided string. It is designed for low-latency look-ups used in auto-complete scenarios. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-terms-enum.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * 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, // field name, string which is the prefix expected in matching terms, timeout and size for max number of results + * } $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 termsEnum(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_terms_enum'; + $method = empty($params['body']) ? 'GET' : 'POST'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Returns information and statistics about terms in the fields of a particular document. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html + * + * @param array{ + * index: string, // (REQUIRED) The index in which the document resides. + * id: string, // The id of the document, when not specified a doc param should be supplied. + * term_statistics: boolean, // Specifies if total term frequency and document frequency should be returned. + * field_statistics: boolean, // Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. + * fields: list, // A comma-separated list of fields to return. + * offsets: boolean, // Specifies if term offsets should be returned. + * positions: boolean, // Specifies if term positions should be returned. + * payloads: boolean, // Specifies if term payloads should be returned. + * preference: string, // Specify the node or shard the operation should be performed on (default: random). + * routing: string, // Specific routing value. + * realtime: boolean, // Specifies if request is real-time as opposed to near-real-time (default: true). + * version: number, // Explicit version number for concurrency control + * version_type: enum, // Specific version type + * 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, // Define parameters and or supply a document to get termvectors for. See documentation. + * } $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 termvectors(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + if (isset($params['id'])) { + $url = '/' . $this->encode($params['index']) . '/_termvectors/' . $this->encode($params['id']); + $method = empty($params['body']) ? 'GET' : 'POST'; + } else { + $url = '/' . $this->encode($params['index']) . '/_termvectors'; + $method = empty($params['body']) ? 'GET' : 'POST'; + } + $url = $this->addQueryString($url, $params, ['term_statistics','field_statistics','fields','offsets','positions','payloads','preference','routing','realtime','version','version_type','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Updates a document with a script or partial document. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html + * + * @param array{ + * id: string, // (REQUIRED) Document ID + * index: string, // (REQUIRED) The name of the index + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before proceeding with the update operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * _source: list, // True or false to return the _source field or not, or a list of fields to return + * _source_excludes: list, // A list of fields to exclude from the returned _source field + * _source_includes: list, // A list of fields to extract and return from the _source field + * lang: string, // The script language (default: painless) + * refresh: enum, // If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes. + * retry_on_conflict: number, // Specify how many times should the operation be retried when a conflict occurs (default: 0) + * routing: string, // Specific routing value + * timeout: time, // Explicit operation timeout + * if_seq_no: number, // only perform the update operation if the last operation that has changed the document has the specified sequence number + * if_primary_term: number, // only perform the update operation if the last operation that has changed the document has the specified primary term + * require_alias: boolean, // When true, requires destination is an alias. Default is false + * 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 request definition requires either `script` or partial `doc` + * } $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 update(array $params = []) + { + $this->checkRequiredParameters(['id','index','body'], $params); + $url = '/' . $this->encode($params['index']) . '/_update/' . $this->encode($params['id']); + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['wait_for_active_shards','_source','_source_excludes','_source_includes','lang','refresh','retry_on_conflict','routing','timeout','if_seq_no','if_primary_term','require_alias','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Performs an update on every document in the index without changing the source, + * for example to pick up a mapping change. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html + * + * @param array{ + * index: list, // (REQUIRED) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * analyzer: string, // The analyzer to use for the query string + * analyze_wildcard: boolean, // Specify whether wildcard and prefix queries should be analyzed (default: false) + * default_operator: enum, // The default operator for query string query (AND or OR) + * df: string, // The field to use as default where no field prefix is given in the query string + * from: number, // Starting offset (default: 0) + * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) + * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) + * conflicts: enum, // What to do when the update by query hits version conflicts? + * expand_wildcards: enum, // Whether to expand wildcard expression to concrete indices that are open, closed or both. + * lenient: boolean, // Specify whether format-based query failures (such as providing text to a numeric field) should be ignored + * pipeline: string, // Ingest pipeline to set on index requests made by this action. (default: none) + * preference: string, // Specify the node or shard the operation should be performed on (default: random) + * q: string, // Query in the Lucene query string syntax + * routing: list, // A comma-separated list of specific routing values + * scroll: time, // Specify how long a consistent view of the index should be maintained for scrolled search + * search_type: enum, // Search operation type + * search_timeout: time, // Explicit timeout for each search request. Defaults to no timeout. + * max_docs: number, // Maximum number of documents to process (default: all documents) + * sort: list, // A comma-separated list of : pairs + * terminate_after: number, // The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. + * stats: list, // Specific 'tag' of the request for logging and statistical purposes + * version: boolean, // Specify whether to return document version as part of a hit + * version_type: boolean, // Should the document increment the version number (internal) on hit or not (reindex) + * request_cache: boolean, // Specify if request cache should be used for this request or not, defaults to index level setting + * refresh: boolean, // Should the affected indexes be refreshed? + * timeout: time, // Time each individual bulk request should wait for shards that are unavailable. + * wait_for_active_shards: string, // Sets the number of shard copies that must be active before proceeding with the update by query operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * scroll_size: number, // Size on the scroll request powering the update by query + * wait_for_completion: boolean, // Should the request should block until the update by query operation is complete. + * requests_per_second: number, // The throttle to set on this request in sub-requests per second. -1 means no throttle. + * slices: number|string, // The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks. Can be set to `auto`. + * 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, // The search definition using the Query DSL + * } $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 updateByQuery(array $params = []) + { + $this->checkRequiredParameters(['index'], $params); + $url = '/' . $this->encode($params['index']) . '/_update_by_query'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['analyzer','analyze_wildcard','default_operator','df','from','ignore_unavailable','allow_no_indices','conflicts','expand_wildcards','lenient','pipeline','preference','q','routing','scroll','search_type','search_timeout','max_docs','sort','terminate_after','stats','version','version_type','request_cache','refresh','timeout','wait_for_active_shards','scroll_size','wait_for_completion','requests_per_second','slices','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + + /** + * Changes the number of requests per second for a particular Update By Query operation. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html + * + * @param array{ + * task_id: string, // (REQUIRED) The task id to rethrottle + * requests_per_second: number, // The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. + * 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 updateByQueryRethrottle(array $params = []) + { + $this->checkRequiredParameters(['task_id','requests_per_second'], $params); + $url = '/_update_by_query/' . $this->encode($params['task_id']) . '/_rethrottle'; + $method = 'POST'; + + $url = $this->addQueryString($url, $params, ['requests_per_second','pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + ]; + return $this->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } +} diff --git a/Elastic/Elasticsearch/Traits/EndpointTrait.php b/Elastic/Elasticsearch/Traits/EndpointTrait.php new file mode 100644 index 0000000..72af8b5 --- /dev/null +++ b/Elastic/Elasticsearch/Traits/EndpointTrait.php @@ -0,0 +1,196 @@ + $v) { + if (is_string($k)) { + return true; + } + } + return false; + } + + /** + * Converts array to comma-separated list; + * Converts boolean value to true', 'false' string + * + * @param mixed $value + */ + private function convertValue($value): string + { + // Convert a boolean value in 'true' or 'false' string + if (is_bool($value)) { + return $value ? 'true' : 'false'; + // Convert to comma-separated list if array + } elseif (is_array($value) && $this->isNestedArray($value) === false) { + return implode(',', $value); + } + return (string) $value; + } + + /** + * Encode a value for a valid URL + * + * @param mixed $value + */ + protected function encode($value): string + { + return urlencode($this->convertValue($value)); + } + + /** + * Returns the URL with the query string from $params + * extracting the array keys specified in $keys + */ + protected function addQueryString(string $url, array $params, array $keys): string + { + $queryParams = []; + foreach ($keys as $k) { + if (isset($params[$k])) { + $queryParams[$k] = $this->convertValue($params[$k]); + } + } + if (empty($queryParams)) { + return $url; + } + return $url . '?' . http_build_query($queryParams); + } + + /** + * Serialize the body using the Content-Type + * + * @param mixed $body + */ + protected function bodySerialize($body, string $contentType): string + { + if (strpos($contentType, 'application/x-ndjson') !== false || + strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== false) { + return NDJsonSerializer::serialize($body, ['remove_null' => false]); + } + if (strpos($contentType, 'application/json') !== false || + strpos($contentType, 'application/vnd.elasticsearch+json') !== false) { + return JsonSerializer::serialize($body, ['remove_null' => false]); + } + throw new ContentTypeException(sprintf( + "The Content-Type %s is not managed by Elasticsearch serializer", + $contentType + )); + } + + /** + * Create a PSR-7 request + * + * @param array|string $body + */ + protected function createRequest(string $method, string $url, array $headers, $body = null): RequestInterface + { + $requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + $streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + + $request = $requestFactory->createRequest($method, $url); + // Body request + if (!empty($body)) { + if (!isset($headers['Content-Type'])) { + throw new ContentTypeException(sprintf( + "The Content-Type is missing for %s %s", + $method, + $url + )); + } + $content = is_string($body) ? $body : $this->bodySerialize($body, $headers['Content-Type']); + $request = $request->withBody($streamFactory->createStream($content)); + } + $headers = $this->buildCompatibilityHeaders($headers); + + // Headers + foreach ($headers as $name => $value) { + $request = $request->withHeader($name, $value); + } + return $request; + } + + /** + * Build the API compatibility headers + * transfrom Content-Type and Accept adding vnd.elasticsearch+ and compatible-with + * + * @see https://github.com/elastic/elasticsearch-php/pull/1142 + */ + protected function buildCompatibilityHeaders(array $headers): array + { + if (isset($headers['Content-Type'])) { + if (preg_match('/application\/([^,]+)$/', $headers['Content-Type'], $matches)) { + $headers['Content-Type'] = sprintf(Client::API_COMPATIBILITY_HEADER, 'application', $matches[1]); + } + } + if (isset($headers['Accept'])) { + $values = explode(',', $headers['Accept']); + foreach ($values as &$value) { + if (preg_match('/(application|text)\/([^,]+)/', $value, $matches)) { + $value = sprintf(Client::API_COMPATIBILITY_HEADER, $matches[1], $matches[2]); + } + } + $headers['Accept'] = implode(',', $values); + } + return $headers; + } + + /** + * Check if the $required parameters are present in $params + * @throws MissingParameterException + */ + protected function checkRequiredParameters(array $required, array $params): void + { + foreach ($required as $req) { + if (!isset($params[$req])) { + throw new MissingParameterException(sprintf( + 'The parameter %s is required', + $req + )); + } + } + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Traits/MessageResponseTrait.php b/Elastic/Elasticsearch/Traits/MessageResponseTrait.php new file mode 100644 index 0000000..b4d5887 --- /dev/null +++ b/Elastic/Elasticsearch/Traits/MessageResponseTrait.php @@ -0,0 +1,94 @@ +response as source object + */ +trait MessageResponseTrait +{ + public function getProtocolVersion() + { + return $this->response->getProtocolVersion(); + } + + public function withProtocolVersion($version) + { + return $this->response->withProtocolVersion($version); + } + + public function getHeaders() + { + return $this->response->getHeaders(); + } + + public function hasHeader($name) + { + return $this->response->hasHeader($name); + } + + public function getHeader($name) + { + return $this->response->getHeader($name); + } + + public function getHeaderLine($name) + { + return $this->response->getHeaderLine($name); + } + + public function withHeader($name, $value) + { + return $this->response->withHeader($name, $value); + } + + public function withAddedHeader($name, $value) + { + return $this->response->withAddedHeader($name, $value); + } + + public function withoutHeader($name) + { + return $this->response->withoutHeader($name); + } + + public function getBody() + { + return $this->response->getBody(); + } + + public function withBody(StreamInterface $body) + { + return $this->response->withBody($body); + } + + public function getStatusCode() + { + return $this->response->getStatusCode(); + } + + public function withStatus($code, $reasonPhrase = '') + { + return $this->response->withStatus($code, $reasonPhrase); + } + + public function getReasonPhrase() + { + return $this->response->getReasonPhrase(); + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Traits/NamespaceTrait.php b/Elastic/Elasticsearch/Traits/NamespaceTrait.php new file mode 100644 index 0000000..f260438 --- /dev/null +++ b/Elastic/Elasticsearch/Traits/NamespaceTrait.php @@ -0,0 +1,357 @@ +namespace['AsyncSearch'])) { + $this->namespace['AsyncSearch'] = new AsyncSearch($this); + } + return $this->namespace['AsyncSearch']; + } + + + public function autoscaling(): Autoscaling + { + if (!isset($this->namespace['Autoscaling'])) { + $this->namespace['Autoscaling'] = new Autoscaling($this); + } + return $this->namespace['Autoscaling']; + } + + + public function cat(): Cat + { + if (!isset($this->namespace['Cat'])) { + $this->namespace['Cat'] = new Cat($this); + } + return $this->namespace['Cat']; + } + + + public function ccr(): Ccr + { + if (!isset($this->namespace['Ccr'])) { + $this->namespace['Ccr'] = new Ccr($this); + } + return $this->namespace['Ccr']; + } + + + public function cluster(): Cluster + { + if (!isset($this->namespace['Cluster'])) { + $this->namespace['Cluster'] = new Cluster($this); + } + return $this->namespace['Cluster']; + } + + + public function danglingIndices(): DanglingIndices + { + if (!isset($this->namespace['DanglingIndices'])) { + $this->namespace['DanglingIndices'] = new DanglingIndices($this); + } + return $this->namespace['DanglingIndices']; + } + + + public function enrich(): Enrich + { + if (!isset($this->namespace['Enrich'])) { + $this->namespace['Enrich'] = new Enrich($this); + } + return $this->namespace['Enrich']; + } + + + public function eql(): Eql + { + if (!isset($this->namespace['Eql'])) { + $this->namespace['Eql'] = new Eql($this); + } + return $this->namespace['Eql']; + } + + + public function features(): Features + { + if (!isset($this->namespace['Features'])) { + $this->namespace['Features'] = new Features($this); + } + return $this->namespace['Features']; + } + + + public function fleet(): Fleet + { + if (!isset($this->namespace['Fleet'])) { + $this->namespace['Fleet'] = new Fleet($this); + } + return $this->namespace['Fleet']; + } + + + public function graph(): Graph + { + if (!isset($this->namespace['Graph'])) { + $this->namespace['Graph'] = new Graph($this); + } + return $this->namespace['Graph']; + } + + + public function ilm(): Ilm + { + if (!isset($this->namespace['Ilm'])) { + $this->namespace['Ilm'] = new Ilm($this); + } + return $this->namespace['Ilm']; + } + + + public function indices(): Indices + { + if (!isset($this->namespace['Indices'])) { + $this->namespace['Indices'] = new Indices($this); + } + return $this->namespace['Indices']; + } + + + public function ingest(): Ingest + { + if (!isset($this->namespace['Ingest'])) { + $this->namespace['Ingest'] = new Ingest($this); + } + return $this->namespace['Ingest']; + } + + + public function license(): License + { + if (!isset($this->namespace['License'])) { + $this->namespace['License'] = new License($this); + } + return $this->namespace['License']; + } + + + public function logstash(): Logstash + { + if (!isset($this->namespace['Logstash'])) { + $this->namespace['Logstash'] = new Logstash($this); + } + return $this->namespace['Logstash']; + } + + + public function migration(): Migration + { + if (!isset($this->namespace['Migration'])) { + $this->namespace['Migration'] = new Migration($this); + } + return $this->namespace['Migration']; + } + + + public function ml(): Ml + { + if (!isset($this->namespace['Ml'])) { + $this->namespace['Ml'] = new Ml($this); + } + return $this->namespace['Ml']; + } + + + public function monitoring(): Monitoring + { + if (!isset($this->namespace['Monitoring'])) { + $this->namespace['Monitoring'] = new Monitoring($this); + } + return $this->namespace['Monitoring']; + } + + + public function nodes(): Nodes + { + if (!isset($this->namespace['Nodes'])) { + $this->namespace['Nodes'] = new Nodes($this); + } + return $this->namespace['Nodes']; + } + + + public function rollup(): Rollup + { + if (!isset($this->namespace['Rollup'])) { + $this->namespace['Rollup'] = new Rollup($this); + } + return $this->namespace['Rollup']; + } + + + public function searchableSnapshots(): SearchableSnapshots + { + if (!isset($this->namespace['SearchableSnapshots'])) { + $this->namespace['SearchableSnapshots'] = new SearchableSnapshots($this); + } + return $this->namespace['SearchableSnapshots']; + } + + + public function security(): Security + { + if (!isset($this->namespace['Security'])) { + $this->namespace['Security'] = new Security($this); + } + return $this->namespace['Security']; + } + + + public function shutdown(): Shutdown + { + if (!isset($this->namespace['Shutdown'])) { + $this->namespace['Shutdown'] = new Shutdown($this); + } + return $this->namespace['Shutdown']; + } + + + public function slm(): Slm + { + if (!isset($this->namespace['Slm'])) { + $this->namespace['Slm'] = new Slm($this); + } + return $this->namespace['Slm']; + } + + + public function snapshot(): Snapshot + { + if (!isset($this->namespace['Snapshot'])) { + $this->namespace['Snapshot'] = new Snapshot($this); + } + return $this->namespace['Snapshot']; + } + + + public function sql(): Sql + { + if (!isset($this->namespace['Sql'])) { + $this->namespace['Sql'] = new Sql($this); + } + return $this->namespace['Sql']; + } + + + public function ssl(): Ssl + { + if (!isset($this->namespace['Ssl'])) { + $this->namespace['Ssl'] = new Ssl($this); + } + return $this->namespace['Ssl']; + } + + + public function tasks(): Tasks + { + if (!isset($this->namespace['Tasks'])) { + $this->namespace['Tasks'] = new Tasks($this); + } + return $this->namespace['Tasks']; + } + + + public function textStructure(): TextStructure + { + if (!isset($this->namespace['TextStructure'])) { + $this->namespace['TextStructure'] = new TextStructure($this); + } + return $this->namespace['TextStructure']; + } + + + public function transform(): Transform + { + if (!isset($this->namespace['Transform'])) { + $this->namespace['Transform'] = new Transform($this); + } + return $this->namespace['Transform']; + } + + + public function watcher(): Watcher + { + if (!isset($this->namespace['Watcher'])) { + $this->namespace['Watcher'] = new Watcher($this); + } + return $this->namespace['Watcher']; + } + + + public function xpack(): Xpack + { + if (!isset($this->namespace['Xpack'])) { + $this->namespace['Xpack'] = new Xpack($this); + } + return $this->namespace['Xpack']; + } +} diff --git a/Elastic/Elasticsearch/Traits/ProductCheckTrait.php b/Elastic/Elasticsearch/Traits/ProductCheckTrait.php new file mode 100644 index 0000000..82e615e --- /dev/null +++ b/Elastic/Elasticsearch/Traits/ProductCheckTrait.php @@ -0,0 +1,38 @@ +getStatusCode(); + if ($statusCode >= 200 && $statusCode < 300) { + $product = $response->getHeaderLine(Elasticsearch::HEADER_CHECK); + if (empty($product) || $product !== Elasticsearch::PRODUCT_NAME) { + throw new ProductCheckException( + 'The client noticed that the server is not Elasticsearch and we do not support this unknown product' + ); + } + } + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Traits/ResponseTrait.php b/Elastic/Elasticsearch/Traits/ResponseTrait.php new file mode 100644 index 0000000..7ff7b0a --- /dev/null +++ b/Elastic/Elasticsearch/Traits/ResponseTrait.php @@ -0,0 +1,33 @@ +response = $response; + return $this; + } + + public function getResponse(): ResponseInterface + { + return $this->response; + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Transport/Adapter/AdapterInterface.php b/Elastic/Elasticsearch/Transport/Adapter/AdapterInterface.php new file mode 100644 index 0000000..b4a6bbd --- /dev/null +++ b/Elastic/Elasticsearch/Transport/Adapter/AdapterInterface.php @@ -0,0 +1,22 @@ + "Elastic\\Elasticsearch\\Transport\\Adapter\\Guzzle", + "Symfony\\Component\\HttpClient\\HttplugClient" => "Elastic\\Elasticsearch\\Transport\\Adapter\\Symfony", + "Symfony\\Component\\HttpClient\\Psr18Client" => "Elastic\\Elasticsearch\\Transport\\Adapter\\Symfony" + ]; +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Transport/Adapter/Guzzle.php b/Elastic/Elasticsearch/Transport/Adapter/Guzzle.php new file mode 100644 index 0000000..dfacc97 --- /dev/null +++ b/Elastic/Elasticsearch/Transport/Adapter/Guzzle.php @@ -0,0 +1,44 @@ + $value) { + switch ($key) { + case RequestOptions::SSL_CERT: + $guzzleConfig[GuzzleOptions::CERT] = $value; + break; + case RequestOptions::SSL_KEY: + $guzzleConfig[GuzzleOptions::SSL_KEY] = $value; + break; + case RequestOptions::SSL_VERIFY: + $guzzleConfig[GuzzleOptions::VERIFY] = $value; + break; + case RequestOptions::SSL_CA: + $guzzleConfig[GuzzleOptions::VERIFY] = $value; + } + } + $class = get_class($client); + return new $class(array_merge($clientOptions, $guzzleConfig)); + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Transport/Adapter/Symfony.php b/Elastic/Elasticsearch/Transport/Adapter/Symfony.php new file mode 100644 index 0000000..892ed4b --- /dev/null +++ b/Elastic/Elasticsearch/Transport/Adapter/Symfony.php @@ -0,0 +1,46 @@ + $value) { + switch ($key) { + case RequestOptions::SSL_CERT: + $symfonyConfig['local_cert'] = $value; + break; + case RequestOptions::SSL_KEY: + $symfonyConfig['local_pk'] = $value; + break; + case RequestOptions::SSL_VERIFY: + $symfonyConfig['verify_host'] = $value; + $symfonyConfig['verify_peer'] = $value; + break; + case RequestOptions::SSL_CA: + $symfonyConfig['cafile'] = $value; + } + } + $class = get_class($client); + $httpClient = HttpClient::create(array_merge($clientOptions, $symfonyConfig)); + return new $class($httpClient); + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Transport/AsyncOnSuccess.php b/Elastic/Elasticsearch/Transport/AsyncOnSuccess.php new file mode 100644 index 0000000..906b1ef --- /dev/null +++ b/Elastic/Elasticsearch/Transport/AsyncOnSuccess.php @@ -0,0 +1,29 @@ +setResponse($response, true); + return $result; + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Transport/AsyncOnSuccessNoException.php b/Elastic/Elasticsearch/Transport/AsyncOnSuccessNoException.php new file mode 100644 index 0000000..1b69a58 --- /dev/null +++ b/Elastic/Elasticsearch/Transport/AsyncOnSuccessNoException.php @@ -0,0 +1,29 @@ +setResponse($response, false); + return $result; + } +} \ No newline at end of file diff --git a/Elastic/Elasticsearch/Transport/RequestOptions.php b/Elastic/Elasticsearch/Transport/RequestOptions.php new file mode 100644 index 0000000..b713719 --- /dev/null +++ b/Elastic/Elasticsearch/Transport/RequestOptions.php @@ -0,0 +1,38 @@ +uri = Psr17FactoryDiscovery::findUriFactory()->createUri($host); + } + + public function markAlive(bool $alive): void + { + $this->alive = $alive; + } + + public function isAlive(): bool + { + return $this->alive; + } + + public function getUri(): UriInterface + { + return $this->uri; + } +} \ No newline at end of file diff --git a/Elastic/Transport/NodePool/NodePoolInterface.php b/Elastic/Transport/NodePool/NodePoolInterface.php new file mode 100644 index 0000000..fe98b34 --- /dev/null +++ b/Elastic/Transport/NodePool/NodePoolInterface.php @@ -0,0 +1,25 @@ +getRequestFactory()->createRequest("HEAD", $node->getUri()); + try { + $response = $this->getClient()->sendRequest($request); + return $response->getStatusCode() === 200; + } catch (Exception $e) { + return false; + } + } + + public function getClient(): ClientInterface + { + if (empty($this->client)) { + $this->client = Psr18ClientDiscovery::find(); + } + return $this->client; + } + + public function getRequestFactory(): RequestFactoryInterface + { + if (empty($this->requestFactory)) { + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + } + return $this->requestFactory; + } +} \ No newline at end of file diff --git a/Elastic/Transport/NodePool/Resurrect/NoResurrect.php b/Elastic/Transport/NodePool/Resurrect/NoResurrect.php new file mode 100644 index 0000000..99b9f8e --- /dev/null +++ b/Elastic/Transport/NodePool/Resurrect/NoResurrect.php @@ -0,0 +1,28 @@ +getNodes())) { + $className = substr(__CLASS__, strrpos(__CLASS__, '\\') + 1); + throw new NoNodeAvailableException(sprintf( + "No node available. Please use %s::setNodes() before calling %s::nextNode().", + $className, + $className + )); + } + $node = current($this->nodes); + if (false === next($this->nodes)) { + reset($this->nodes); + } + return $node; + } +} \ No newline at end of file diff --git a/Elastic/Transport/NodePool/Selector/SelectorInterface.php b/Elastic/Transport/NodePool/Selector/SelectorInterface.php new file mode 100644 index 0000000..2129ea4 --- /dev/null +++ b/Elastic/Transport/NodePool/Selector/SelectorInterface.php @@ -0,0 +1,32 @@ +nodes = $nodes; + } + + public function getNodes(): array + { + return $this->nodes; + } +} \ No newline at end of file diff --git a/Elastic/Transport/NodePool/SimpleNodePool.php b/Elastic/Transport/NodePool/SimpleNodePool.php new file mode 100644 index 0000000..01f26df --- /dev/null +++ b/Elastic/Transport/NodePool/SimpleNodePool.php @@ -0,0 +1,82 @@ +selector = $selector; + $this->resurrect = $resurrect; + } + + public function setHosts(array $hosts): self + { + $this->nodes = []; + foreach ($hosts as $host) { + $this->nodes[] = new Node($host); + } + shuffle($this->nodes); // randomize for use different hosts on each execution + $this->selector->setNodes($this->nodes); + + return $this; + } + + public function nextNode(): Node + { + $totNodes = count($this->nodes); + $dead = 0; + + while ($dead < $totNodes) { + $next = $this->selector->nextNode(); + if ($next->isAlive()) { + return $next; + } + if ($this->resurrect->ping($next)) { + $next->markAlive(true); + return $next; + } + $dead++; + } + + throw new NoNodeAvailableException(sprintf( + 'No alive nodes. All the %d nodes seem to be down.', + $totNodes + )); + } +} \ No newline at end of file diff --git a/Elastic/Transport/Serializer/CsvSerializer.php b/Elastic/Transport/Serializer/CsvSerializer.php new file mode 100644 index 0000000..140359d --- /dev/null +++ b/Elastic/Transport/Serializer/CsvSerializer.php @@ -0,0 +1,62 @@ + (bool) enable/disable the removing of + * null values (default is true) + * + * @param mixed $data + */ + public static function serialize($data, array $options = []): string + { + if (empty($data)) { + return '{}'; + } + if (is_string($data)) { + return $data; + } + try { + $removeNull = $options['remove_null'] ?? true; + if ($removeNull) { + Utility::removeNullValue($data); + } + return json_encode($data, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE + JSON_THROW_ON_ERROR); + } catch (JsonException $e) { + throw new InvalidJsonException(sprintf( + "I cannot serialize to Json: %s", + $e->getMessage() + )); + } + } + + /** + * The available options are: + * 'type' => (string) specify if the output should be an array + * or an object (default is array) + * + * @inheritdoc + */ + public static function unserialize(string $data, array $options = []) + { + try { + $type = $options['type'] ?? 'array'; + if (!in_array($type, ['object', 'array'])) { + throw new UndefinedPropertyException("The unserialize 'type' option must be object or array"); + } + return json_decode($data, $type === 'array', 512, JSON_THROW_ON_ERROR); + } catch (JsonException $e) { + throw new InvalidJsonException(sprintf( + "Not a valid Json: %s", + $e->getMessage() + )); + } + } +} \ No newline at end of file diff --git a/Elastic/Transport/Serializer/NDJsonSerializer.php b/Elastic/Transport/Serializer/NDJsonSerializer.php new file mode 100644 index 0000000..8a76f24 --- /dev/null +++ b/Elastic/Transport/Serializer/NDJsonSerializer.php @@ -0,0 +1,75 @@ + (bool) enable/disable the removing of + * null values (default is true) + * + * @param array $data + */ + public static function serialize($data, array $options = []): string + { + $result = ''; + foreach ($data as $row) { + if (empty($row)) { + $result .= "{}\n"; + continue; + } + $result .= JsonSerializer::serialize($row, $options) . "\n"; + } + return $result; + } + + /** + * The available options are: + * 'type' => (string) specify if the array result should contain object + * or array (default is array) + * + * @inheritdoc + */ + public static function unserialize(string $data, array $options = []) + { + $array = explode(strpos($data, "\r\n") !== false ? "\r\n" : "\n", $data); + $result = []; + foreach ($array as $json) { + if (empty($json)) { + continue; + } + try { + $result[] = JsonSerializer::unserialize($json, $options); + } catch (JsonException $e) { + throw new InvalidJsonException(sprintf( + "Not a valid NDJson: %s", + $e->getMessage() + )); + } + } + $type = $options['type'] ?? 'array'; + return $type === 'array' ? $result : new ArrayObject($result); + } +} \ No newline at end of file diff --git a/Elastic/Transport/Serializer/SerializerInterface.php b/Elastic/Transport/Serializer/SerializerInterface.php new file mode 100644 index 0000000..6dfef93 --- /dev/null +++ b/Elastic/Transport/Serializer/SerializerInterface.php @@ -0,0 +1,32 @@ + &$value) { + if (is_object($value) || is_array($value)) { + self::removeNullValue($value); + } + if (null === $value) { + if (is_array($data)) { + unset($data[$property]); + } + if (is_object($data)) { + unset($data->$property); + } + } + } + } +} \ No newline at end of file diff --git a/Elastic/Transport/Serializer/XmlSerializer.php b/Elastic/Transport/Serializer/XmlSerializer.php new file mode 100644 index 0000000..45fc6f4 --- /dev/null +++ b/Elastic/Transport/Serializer/XmlSerializer.php @@ -0,0 +1,56 @@ +asXML(); + return false === $xml ? '' : $xml; + } + throw new InvalidXmlException(sprintf( + "Not a valid SimpleXMLElement: %s", + serialize($data) + )); + } + + /** + * @return SimpleXMLElement + */ + public static function unserialize(string $data, array $options = []): SimpleXMLElement + { + $result = simplexml_load_string($data); + if (false === $result) { + $errors = libxml_get_errors(); + libxml_clear_errors(); + throw new InvalidXmlException(sprintf( + "Not a valid XML: %s", + serialize($errors) + )); + } + return $result; + } +} \ No newline at end of file diff --git a/Elastic/Transport/Transport.php b/Elastic/Transport/Transport.php new file mode 100644 index 0000000..25c4b28 --- /dev/null +++ b/Elastic/Transport/Transport.php @@ -0,0 +1,450 @@ +client = $client; + $this->nodePool = $nodePool; + $this->logger = $logger; + } + + public function getClient(): ClientInterface + { + return $this->client; + } + + public function getNodePool(): NodePoolInterface + { + return $this->nodePool; + } + + public function getLogger(): LoggerInterface + { + return $this->logger; + } + + public function setHeader(string $name, string $value): self + { + $this->headers[$name] = $value; + return $this; + } + + /** + * @throws InvalidArgumentException + */ + public function setRetries(int $num): self + { + if ($num < 0) { + throw new InvalidArgumentException('The retries number must be a positive integer'); + } + $this->retries = $num; + return $this; + } + + public function getRetries(): int + { + return $this->retries; + } + + public function getHeaders(): array + { + return $this->headers; + } + + public function setUserInfo(string $user, string $password = ''): self + { + $this->user = $user; + $this->password = $password; + return $this; + } + + public function setUserAgent(string $name, string $version): self + { + $this->headers['User-Agent'] = sprintf( + "%s/%s (%s %s; PHP %s)", + $name, + $version, + PHP_OS, + $this->getOSVersion(), + phpversion() + ); + return $this; + } + + /** + * Set the x-elastic-client-meta header + * + * The header format is specified by the following regex: + * ^[a-z]{1,}=[a-z0-9\.\-]{1,}(?:,[a-z]{1,}=[a-z0-9\.\-]+)*$ + */ + public function setElasticMetaHeader(string $clientName, string $clientVersion, bool $async = false): self + { + $phpSemVersion = sprintf("%d.%d.%d", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION); + $meta = sprintf( + "%s=%s,php=%s,t=%s,a=%d", + $clientName, + $this->purgePreReleaseTag($clientVersion), + $phpSemVersion, + $this->purgePreReleaseTag(self::VERSION), + $async ? 1 : 0 // 0=syncronous, 1=asynchronous + ); + $lib = $this->getClientLibraryInfo(); + if (!empty($lib)) { + $meta .= sprintf(",%s=%s", $lib[0], $lib[1]); + } + $this->headers['x-elastic-client-meta'] = $meta; + return $this; + } + + /** + * Remove pre-release suffix with a single 'p' letter + */ + private function purgePreReleaseTag(string $version): string + { + return str_replace(['alpha', 'beta', 'snapshot', 'rc', 'pre'], 'p', strtolower($version)); + } + + public function getLastRequest(): RequestInterface + { + return $this->lastRequest; + } + + public function getLastResponse(): ResponseInterface + { + return $this->lastResponse; + } + + /** + * Setup the headers, if not already present + */ + private function setupHeaders(RequestInterface $request): RequestInterface + { + foreach ($this->headers as $name => $value) { + if (!$request->hasHeader($name)) { + $request = $request->withHeader($name, $value); + } + } + return $request; + } + + /** + * Setup the user info, if not already present + */ + private function setupUserInfo(RequestInterface $request): RequestInterface + { + $uri = $request->getUri(); + if (empty($uri->getUserInfo())) { + if (isset($this->user)) { + $request = $request->withUri($uri->withUserInfo($this->user, $this->password)); + } + } + return $request; + } + + /** + * Setup the connection Uri + */ + private function setupConnectionUri(Node $node, RequestInterface $request): RequestInterface + { + $uri = $node->getUri(); + + return $request->withUri( + $request->getUri() + ->withHost($uri->getHost()) + ->withPort($uri->getPort()) + ->withScheme($uri->getScheme()) + ); + } + + private function decorateRequest(RequestInterface $request): RequestInterface + { + $request = $this->setupHeaders($request); + return $this->setupUserInfo($request); + } + + private function logHeaders(MessageInterface $message): void + { + $this->logger->debug(sprintf( + "Headers: %s\nBody: %s", + json_encode($message->getHeaders()), + (string) $message->getBody() + )); + } + + private function logRequest(string $title, RequestInterface $request): void + { + $this->logger->info(sprintf( + "%s: %s %s", + $title, + $request->getMethod(), + (string) $request->getUri() + ), [ + 'request' => $request + ]); + $this->logHeaders($request); + } + + private function logResponse(string $title, ResponseInterface $response, int $retry): void + { + $this->logger->info(sprintf( + "%s (retry %d): %d", + $title, + $retry, + $response->getStatusCode() + ), [ + 'response' => $response, + 'retry' => $retry + ]); + $this->logHeaders($response); + } + + /** + * @throws NoNodeAvailableException + * @throws ClientExceptionInterface + */ + public function sendRequest(RequestInterface $request): ResponseInterface + { + if (empty($request->getUri()->getHost())) { + $node = $this->nodePool->nextNode(); + $request = $this->setupConnectionUri($node, $request); + } + $request = $this->decorateRequest($request); + $this->lastRequest = $request; + $this->logRequest("Request", $request); + + $count = -1; + while ($count < $this->getRetries()) { + try { + $count++; + $response = $this->client->sendRequest($request); + + $this->lastResponse = $response; + $this->logResponse("Response", $response, $count); + + return $response; + } catch (NetworkExceptionInterface $e) { + $this->logger->error(sprintf("Retry %d: %s", $count, $e->getMessage())); + if (isset($node)) { + $node->markAlive(false); + $node = $this->nodePool->nextNode(); + $request = $this->setupConnectionUri($node, $request); + } + } catch (ClientExceptionInterface $e) { + $this->logger->error(sprintf("Retry %d: %s", $count, $e->getMessage())); + throw $e; + } + } + $exceededMsg = sprintf("Exceeded maximum number of retries (%d)", $this->getRetries()); + $this->logger->error($exceededMsg); + throw new NoNodeAvailableException($exceededMsg); + } + + public function setAsyncClient(HttpAsyncClient $asyncClient): self + { + $this->asyncClient = $asyncClient; + return $this; + } + + /** + * @throws NoAsyncClientException + */ + public function getAsyncClient(): HttpAsyncClient + { + if (!empty($this->asyncClient)) { + return $this->asyncClient; + } + if ($this->client instanceof HttpAsyncClient) { + return $this->client; + } + try { + $this->asyncClient = HttpAsyncClientDiscovery::find(); + } catch (Exception $e) { + throw new NoAsyncClientException(sprintf( + "I did not find any HTTP library with HttpAsyncClient interface. " . + "Make sure to install a package providing \"php-http/async-client-implementation\". " . + "You can also set a specific async library using %s::setAsyncClient()", + self::class + )); + } + return $this->asyncClient; + } + + public function setAsyncOnSuccess(OnSuccessInterface $success): self + { + $this->onAsyncSuccess = $success; + return $this; + } + + public function getAsyncOnSuccess(): OnSuccessInterface + { + if (empty($this->onAsyncSuccess)) { + $this->onAsyncSuccess = new OnSuccessDefault(); + } + return $this->onAsyncSuccess; + } + + public function setAsyncOnFailure(OnFailureInterface $failure): self + { + $this->onAsyncFailure = $failure; + return $this; + } + + public function getAsyncOnFailure(): OnFailureInterface + { + if (empty($this->onAsyncFailure)) { + $this->onAsyncFailure = new OnFailureDefault(); + } + return $this->onAsyncFailure; + } + + /** + * @throws Exception + */ + public function sendAsyncRequest(RequestInterface $request): Promise + { + $client = $this->getAsyncClient(); + $node = null; + if (empty($request->getUri()->getHost())) { + $node = $this->nodePool->nextNode(); + $request = $this->setupConnectionUri($node, $request); + } + $request = $this->decorateRequest($request); + $this->lastRequest = $request; + $this->logRequest("Async Request", $request); + + $count = 0; + $promise = $client->sendAsyncRequest($request); + + // onFulfilled callable + $onFulfilled = function (ResponseInterface $response) use (&$count) { + $this->lastResponse = $response; + $this->logResponse("Async Response", $response, $count); + return $this->getAsyncOnSuccess()->success($response, $count); + }; + + // onRejected callable + $onRejected = function (Exception $e) use ($client, $request, &$count, $node) { + $this->logger->error(sprintf("Retry %d: %s", $count, $e->getMessage())); + $this->getAsyncOnFailure()->failure($e, $request, $count, $node ?? null); + if (isset($node)) { + $node->markAlive(false); + $node = $this->nodePool->nextNode(); + $request = $this->setupConnectionUri($node, $request); + } + $count++; + return $client->sendAsyncRequest($request); + }; + + // Add getRetries() callables using then() + for ($i=0; $i < $this->getRetries(); $i++) { + $promise = $promise->then($onFulfilled, $onRejected); + } + // Add the last getRetries()+1 callable for managing the exceeded error + $promise = $promise->then($onFulfilled, function(Exception $e) use (&$count) { + $exceededMsg = sprintf("Exceeded maximum number of retries (%d)", $this->getRetries()); + $this->logger->error(sprintf("Retry %d: %s", $count, $e->getMessage())); + $this->logger->error($exceededMsg); + throw new NoNodeAvailableException(sprintf("%s: %s", $exceededMsg, $e->getMessage())); + }); + return $promise; + } + + /** + * Get the OS version using php_uname if available + * otherwise it returns an empty string + */ + private function getOSVersion(): string + { + if (!isset($this->OSVersion)) { + $disable_functions = (string) ini_get('disable_functions'); + $this->OSVersion = strpos(strtolower($disable_functions), 'php_uname') !== false + ? '' + : php_uname("r"); + } + return $this->OSVersion; + } + + /** + * Returns the name and the version of the Client HTTP library used + * Here a list of supported libraries: + * gu => guzzlehttp/guzzle + * sy => symfony/http-client + */ + private function getClientLibraryInfo(): array + { + $clientClass = get_class($this->client); + if ($clientClass === 'GuzzleHttp\Client') { + return ['gu', InstalledVersions::getPrettyVersion('guzzlehttp/guzzle')]; + } + if (false !== strpos($clientClass, 'Symfony\Component\HttpClient')) { + return ['sy', InstalledVersions::getPrettyVersion('symfony/http-client')]; + } + return []; + } +} diff --git a/Elastic/Transport/TransportBuilder.php b/Elastic/Transport/TransportBuilder.php new file mode 100644 index 0000000..ec7888c --- /dev/null +++ b/Elastic/Transport/TransportBuilder.php @@ -0,0 +1,132 @@ +client = $client; + return $this; + } + + public function getClient(): ClientInterface + { + if (empty($this->client)) { + $this->client = Psr18ClientDiscovery::find(); + } + return $this->client; + } + + public function setNodePool(NodePoolInterface $nodePool): self + { + $this->nodePool = $nodePool; + return $this; + } + + public function getNodePool(): NodePoolInterface + { + if (empty($this->nodePool)) { + $this->nodePool = new SimpleNodePool( + new RoundRobin(), + new NoResurrect() + ); + } + return $this->nodePool; + } + + public function setLogger(LoggerInterface $logger): self + { + $this->logger = $logger; + return $this; + } + + public function getLogger(): LoggerInterface + { + if (empty($this->logger)) { + $this->logger = new NullLogger(); + } + return $this->logger; + } + + public function setHosts(array $hosts): self + { + $this->hosts = $hosts; + return $this; + } + + public function getHosts(): array + { + return $this->hosts; + } + + public function setCloudId(string $cloudId): self + { + $this->hosts = [$this->parseElasticCloudId($cloudId)]; + return $this; + } + + public function build(): Transport + { + return new Transport( + $this->getClient(), + $this->getNodePool()->setHosts($this->hosts), + $this->getLogger() + ); + } + + /** + * Return the URL of Elastic Cloud from the Cloud ID + */ + private function parseElasticCloudId(string $cloudId): string + { + try { + list($name, $encoded) = explode(':', $cloudId); + list($uri, $uuids) = explode('$', base64_decode($encoded)); + list($es,) = explode(':', $uuids); + + return sprintf("https://%s.%s", $es, $uri); + } catch (Throwable $t) { + throw new Exception\CloudIdParseException( + 'Cloud ID not valid' + ); + } + } +} \ No newline at end of file diff --git a/Http/Discovery/ClassDiscovery.php b/Http/Discovery/ClassDiscovery.php new file mode 100644 index 0000000..4f47f3c --- /dev/null +++ b/Http/Discovery/ClassDiscovery.php @@ -0,0 +1,252 @@ + + * @author Márk Sági-Kazár + * @author Tobias Nyholm + */ +abstract class ClassDiscovery +{ + /** + * A list of strategies to find classes. + * + * @var array + */ + private static $strategies = [ + Strategy\CommonClassesStrategy::class, + Strategy\CommonPsr17ClassesStrategy::class, + Strategy\PuliBetaStrategy::class, + ]; + + private static $deprecatedStrategies = [ + Strategy\PuliBetaStrategy::class => true, + ]; + + /** + * Discovery cache to make the second time we use discovery faster. + * + * @var array + */ + private static $cache = []; + + /** + * Finds a class. + * + * @param string $type + * + * @return string|\Closure + * + * @throws DiscoveryFailedException + */ + protected static function findOneByType($type) + { + // Look in the cache + if (null !== ($class = self::getFromCache($type))) { + return $class; + } + + $exceptions = []; + foreach (self::$strategies as $strategy) { + try { + $candidates = call_user_func($strategy.'::getCandidates', $type); + } catch (StrategyUnavailableException $e) { + if (!isset(self::$deprecatedStrategies[$strategy])) { + $exceptions[] = $e; + } + + continue; + } + + foreach ($candidates as $candidate) { + if (isset($candidate['condition'])) { + if (!self::evaluateCondition($candidate['condition'])) { + continue; + } + } + + // save the result for later use + self::storeInCache($type, $candidate); + + return $candidate['class']; + } + + $exceptions[] = new NoCandidateFoundException($strategy, $candidates); + } + + throw DiscoveryFailedException::create($exceptions); + } + + /** + * Get a value from cache. + * + * @param string $type + * + * @return string|null + */ + private static function getFromCache($type) + { + if (!isset(self::$cache[$type])) { + return; + } + + $candidate = self::$cache[$type]; + if (isset($candidate['condition'])) { + if (!self::evaluateCondition($candidate['condition'])) { + return; + } + } + + return $candidate['class']; + } + + /** + * Store a value in cache. + * + * @param string $type + * @param string $class + */ + private static function storeInCache($type, $class) + { + self::$cache[$type] = $class; + } + + /** + * Set new strategies and clear the cache. + * + * @param array $strategies string array of fully qualified class name to a DiscoveryStrategy + */ + public static function setStrategies(array $strategies) + { + self::$strategies = $strategies; + self::clearCache(); + } + + /** + * Returns the currently configured discovery strategies as fully qualified class names. + * + * @return string[] + */ + public static function getStrategies(): iterable + { + return self::$strategies; + } + + /** + * Append a strategy at the end of the strategy queue. + * + * @param string $strategy Fully qualified class name to a DiscoveryStrategy + */ + public static function appendStrategy($strategy) + { + self::$strategies[] = $strategy; + self::clearCache(); + } + + /** + * Prepend a strategy at the beginning of the strategy queue. + * + * @param string $strategy Fully qualified class name to a DiscoveryStrategy + */ + public static function prependStrategy($strategy) + { + array_unshift(self::$strategies, $strategy); + self::clearCache(); + } + + /** + * Clear the cache. + */ + public static function clearCache() + { + self::$cache = []; + } + + /** + * Evaluates conditions to boolean. + * + * @param mixed $condition + * + * @return bool + */ + protected static function evaluateCondition($condition) + { + if (is_string($condition)) { + // Should be extended for functions, extensions??? + return self::safeClassExists($condition); + } + if (is_callable($condition)) { + return (bool) $condition(); + } + if (is_bool($condition)) { + return $condition; + } + if (is_array($condition)) { + foreach ($condition as $c) { + if (false === static::evaluateCondition($c)) { + // Immediately stop execution if the condition is false + return false; + } + } + + return true; + } + + return false; + } + + /** + * Get an instance of the $class. + * + * @param string|\Closure $class a FQCN of a class or a closure that instantiate the class + * + * @return object + * + * @throws ClassInstantiationFailedException + */ + protected static function instantiateClass($class) + { + try { + if (is_string($class)) { + return new $class(); + } + + if (is_callable($class)) { + return $class(); + } + } catch (\Exception $e) { + throw new ClassInstantiationFailedException('Unexpected exception when instantiating class.', 0, $e); + } + + throw new ClassInstantiationFailedException('Could not instantiate class because parameter is neither a callable nor a string'); + } + + /** + * We want to do a "safe" version of PHP's "class_exists" because Magento has a bug + * (or they call it a "feature"). Magento is throwing an exception if you do class_exists() + * on a class that ends with "Factory" and if that file does not exits. + * + * This function will catch all potential exceptions and make sure it returns a boolean. + * + * @param string $class + * @param bool $autoload + * + * @return bool + */ + public static function safeClassExists($class) + { + try { + return class_exists($class) || interface_exists($class); + } catch (\Exception $e) { + return false; + } + } +} diff --git a/Http/Discovery/Exception.php b/Http/Discovery/Exception.php new file mode 100644 index 0000000..58b0523 --- /dev/null +++ b/Http/Discovery/Exception.php @@ -0,0 +1,14 @@ + + */ +interface Exception extends Throwable +{ +} diff --git a/Http/Discovery/Exception/ClassInstantiationFailedException.php b/Http/Discovery/Exception/ClassInstantiationFailedException.php new file mode 100644 index 0000000..e95bf5d --- /dev/null +++ b/Http/Discovery/Exception/ClassInstantiationFailedException.php @@ -0,0 +1,14 @@ + + */ +final class ClassInstantiationFailedException extends \RuntimeException implements Exception +{ +} diff --git a/Http/Discovery/Exception/DiscoveryFailedException.php b/Http/Discovery/Exception/DiscoveryFailedException.php new file mode 100644 index 0000000..304b727 --- /dev/null +++ b/Http/Discovery/Exception/DiscoveryFailedException.php @@ -0,0 +1,51 @@ + + */ +final class DiscoveryFailedException extends \Exception implements Exception +{ + /** + * @var \Exception[] + */ + private $exceptions; + + /** + * @param string $message + * @param \Exception[] $exceptions + */ + public function __construct($message, array $exceptions = []) + { + $this->exceptions = $exceptions; + + parent::__construct($message); + } + + /** + * @param \Exception[] $exceptions + */ + public static function create($exceptions) + { + $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors'; + foreach ($exceptions as $e) { + $message .= "\n - ".$e->getMessage(); + } + $message .= "\n\n"; + + return new self($message, $exceptions); + } + + /** + * @return \Exception[] + */ + public function getExceptions() + { + return $this->exceptions; + } +} diff --git a/Http/Discovery/Exception/NoCandidateFoundException.php b/Http/Discovery/Exception/NoCandidateFoundException.php new file mode 100644 index 0000000..32f65db --- /dev/null +++ b/Http/Discovery/Exception/NoCandidateFoundException.php @@ -0,0 +1,47 @@ + + */ +final class NoCandidateFoundException extends \Exception implements Exception +{ + /** + * @param string $strategy + */ + public function __construct($strategy, array $candidates) + { + $classes = array_map( + function ($a) { + return $a['class']; + }, + $candidates + ); + + $message = sprintf( + 'No valid candidate found using strategy "%s". We tested the following candidates: %s.', + $strategy, + implode(', ', array_map([$this, 'stringify'], $classes)) + ); + + parent::__construct($message); + } + + private function stringify($mixed) + { + if (is_string($mixed)) { + return $mixed; + } + + if (is_array($mixed) && 2 === count($mixed)) { + return sprintf('%s::%s', $this->stringify($mixed[0]), $mixed[1]); + } + + return is_object($mixed) ? get_class($mixed) : gettype($mixed); + } +} diff --git a/Http/Discovery/Exception/NotFoundException.php b/Http/Discovery/Exception/NotFoundException.php new file mode 100644 index 0000000..ef8b9c5 --- /dev/null +++ b/Http/Discovery/Exception/NotFoundException.php @@ -0,0 +1,16 @@ + + */ +/* final */ class NotFoundException extends \RuntimeException implements Exception +{ +} diff --git a/Http/Discovery/Exception/PuliUnavailableException.php b/Http/Discovery/Exception/PuliUnavailableException.php new file mode 100644 index 0000000..a6ade73 --- /dev/null +++ b/Http/Discovery/Exception/PuliUnavailableException.php @@ -0,0 +1,12 @@ + + */ +final class PuliUnavailableException extends StrategyUnavailableException +{ +} diff --git a/Http/Discovery/Exception/StrategyUnavailableException.php b/Http/Discovery/Exception/StrategyUnavailableException.php new file mode 100644 index 0000000..89ecf35 --- /dev/null +++ b/Http/Discovery/Exception/StrategyUnavailableException.php @@ -0,0 +1,15 @@ + + */ +class StrategyUnavailableException extends \RuntimeException implements Exception +{ +} diff --git a/Http/Discovery/HttpAsyncClientDiscovery.php b/Http/Discovery/HttpAsyncClientDiscovery.php new file mode 100644 index 0000000..a0c4d5b --- /dev/null +++ b/Http/Discovery/HttpAsyncClientDiscovery.php @@ -0,0 +1,32 @@ + + */ +final class HttpAsyncClientDiscovery extends ClassDiscovery +{ + /** + * Finds an HTTP Async Client. + * + * @return HttpAsyncClient + * + * @throws Exception\NotFoundException + */ + public static function find() + { + try { + $asyncClient = static::findOneByType(HttpAsyncClient::class); + } catch (DiscoveryFailedException $e) { + throw new NotFoundException('No HTTPlug async clients found. Make sure to install a package providing "php-http/async-client-implementation". Example: "php-http/guzzle6-adapter".', 0, $e); + } + + return static::instantiateClass($asyncClient); + } +} diff --git a/Http/Discovery/HttpClientDiscovery.php b/Http/Discovery/HttpClientDiscovery.php new file mode 100644 index 0000000..2072b94 --- /dev/null +++ b/Http/Discovery/HttpClientDiscovery.php @@ -0,0 +1,32 @@ + + */ +final class HttpClientDiscovery extends ClassDiscovery +{ + /** + * Finds an HTTP Client. + * + * @return HttpClient + * + * @throws Exception\NotFoundException + */ + public static function find() + { + try { + $client = static::findOneByType(HttpClient::class); + } catch (DiscoveryFailedException $e) { + throw new NotFoundException('No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation". Example: "php-http/guzzle6-adapter".', 0, $e); + } + + return static::instantiateClass($client); + } +} diff --git a/Http/Discovery/LICENSE b/Http/Discovery/LICENSE new file mode 100644 index 0000000..4558d6f --- /dev/null +++ b/Http/Discovery/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015-2016 PHP HTTP Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Http/Discovery/MessageFactoryDiscovery.php b/Http/Discovery/MessageFactoryDiscovery.php new file mode 100644 index 0000000..659916d --- /dev/null +++ b/Http/Discovery/MessageFactoryDiscovery.php @@ -0,0 +1,34 @@ + + * + * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery. + */ +final class MessageFactoryDiscovery extends ClassDiscovery +{ + /** + * Finds a Message Factory. + * + * @return MessageFactory + * + * @throws Exception\NotFoundException + */ + public static function find() + { + try { + $messageFactory = static::findOneByType(MessageFactory::class); + } catch (DiscoveryFailedException $e) { + throw new NotFoundException('No message factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.', 0, $e); + } + + return static::instantiateClass($messageFactory); + } +} diff --git a/Http/Discovery/NotFoundException.php b/Http/Discovery/NotFoundException.php new file mode 100644 index 0000000..d59dadb --- /dev/null +++ b/Http/Discovery/NotFoundException.php @@ -0,0 +1,14 @@ + + * + * @deprecated since since version 1.0, and will be removed in 2.0. Use {@link \Http\Discovery\Exception\NotFoundException} instead. + */ +final class NotFoundException extends \Http\Discovery\Exception\NotFoundException +{ +} diff --git a/Http/Discovery/Psr17FactoryDiscovery.php b/Http/Discovery/Psr17FactoryDiscovery.php new file mode 100644 index 0000000..a73c641 --- /dev/null +++ b/Http/Discovery/Psr17FactoryDiscovery.php @@ -0,0 +1,136 @@ + + */ +final class Psr17FactoryDiscovery extends ClassDiscovery +{ + private static function createException($type, Exception $e) + { + return new \Http\Discovery\Exception\NotFoundException( + 'No PSR-17 '.$type.' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation', + 0, + $e + ); + } + + /** + * @return RequestFactoryInterface + * + * @throws Exception\NotFoundException + */ + public static function findRequestFactory() + { + try { + $messageFactory = static::findOneByType(RequestFactoryInterface::class); + } catch (DiscoveryFailedException $e) { + throw self::createException('request factory', $e); + } + + return static::instantiateClass($messageFactory); + } + + /** + * @return ResponseFactoryInterface + * + * @throws Exception\NotFoundException + */ + public static function findResponseFactory() + { + try { + $messageFactory = static::findOneByType(ResponseFactoryInterface::class); + } catch (DiscoveryFailedException $e) { + throw self::createException('response factory', $e); + } + + return static::instantiateClass($messageFactory); + } + + /** + * @return ServerRequestFactoryInterface + * + * @throws Exception\NotFoundException + */ + public static function findServerRequestFactory() + { + try { + $messageFactory = static::findOneByType(ServerRequestFactoryInterface::class); + } catch (DiscoveryFailedException $e) { + throw self::createException('server request factory', $e); + } + + return static::instantiateClass($messageFactory); + } + + /** + * @return StreamFactoryInterface + * + * @throws Exception\NotFoundException + */ + public static function findStreamFactory() + { + try { + $messageFactory = static::findOneByType(StreamFactoryInterface::class); + } catch (DiscoveryFailedException $e) { + throw self::createException('stream factory', $e); + } + + return static::instantiateClass($messageFactory); + } + + /** + * @return UploadedFileFactoryInterface + * + * @throws Exception\NotFoundException + */ + public static function findUploadedFileFactory() + { + try { + $messageFactory = static::findOneByType(UploadedFileFactoryInterface::class); + } catch (DiscoveryFailedException $e) { + throw self::createException('uploaded file factory', $e); + } + + return static::instantiateClass($messageFactory); + } + + /** + * @return UriFactoryInterface + * + * @throws Exception\NotFoundException + */ + public static function findUriFactory() + { + try { + $messageFactory = static::findOneByType(UriFactoryInterface::class); + } catch (DiscoveryFailedException $e) { + throw self::createException('url factory', $e); + } + + return static::instantiateClass($messageFactory); + } + + /** + * @return UriFactoryInterface + * + * @throws Exception\NotFoundException + * + * @deprecated This will be removed in 2.0. Consider using the findUriFactory() method. + */ + public static function findUrlFactory() + { + return static::findUriFactory(); + } +} diff --git a/Http/Discovery/Psr18ClientDiscovery.php b/Http/Discovery/Psr18ClientDiscovery.php new file mode 100644 index 0000000..dfd2dd1 --- /dev/null +++ b/Http/Discovery/Psr18ClientDiscovery.php @@ -0,0 +1,32 @@ + + */ +final class Psr18ClientDiscovery extends ClassDiscovery +{ + /** + * Finds a PSR-18 HTTP Client. + * + * @return ClientInterface + * + * @throws Exception\NotFoundException + */ + public static function find() + { + try { + $client = static::findOneByType(ClientInterface::class); + } catch (DiscoveryFailedException $e) { + throw new \Http\Discovery\Exception\NotFoundException('No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle7-adapter".', 0, $e); + } + + return static::instantiateClass($client); + } +} diff --git a/Http/Discovery/Strategy/CommonClassesStrategy.php b/Http/Discovery/Strategy/CommonClassesStrategy.php new file mode 100644 index 0000000..8bddbe8 --- /dev/null +++ b/Http/Discovery/Strategy/CommonClassesStrategy.php @@ -0,0 +1,189 @@ + + */ +final class CommonClassesStrategy implements DiscoveryStrategy +{ + /** + * @var array + */ + private static $classes = [ + MessageFactory::class => [ + ['class' => NyholmHttplugFactory::class, 'condition' => [NyholmHttplugFactory::class]], + ['class' => GuzzleMessageFactory::class, 'condition' => [GuzzleRequest::class, GuzzleMessageFactory::class]], + ['class' => DiactorosMessageFactory::class, 'condition' => [ZendDiactorosRequest::class, DiactorosMessageFactory::class]], + ['class' => DiactorosMessageFactory::class, 'condition' => [DiactorosRequest::class, DiactorosMessageFactory::class]], + ['class' => SlimMessageFactory::class, 'condition' => [SlimRequest::class, SlimMessageFactory::class]], + ], + StreamFactory::class => [ + ['class' => NyholmHttplugFactory::class, 'condition' => [NyholmHttplugFactory::class]], + ['class' => GuzzleStreamFactory::class, 'condition' => [GuzzleRequest::class, GuzzleStreamFactory::class]], + ['class' => DiactorosStreamFactory::class, 'condition' => [ZendDiactorosRequest::class, DiactorosStreamFactory::class]], + ['class' => DiactorosStreamFactory::class, 'condition' => [DiactorosRequest::class, DiactorosStreamFactory::class]], + ['class' => SlimStreamFactory::class, 'condition' => [SlimRequest::class, SlimStreamFactory::class]], + ], + UriFactory::class => [ + ['class' => NyholmHttplugFactory::class, 'condition' => [NyholmHttplugFactory::class]], + ['class' => GuzzleUriFactory::class, 'condition' => [GuzzleRequest::class, GuzzleUriFactory::class]], + ['class' => DiactorosUriFactory::class, 'condition' => [ZendDiactorosRequest::class, DiactorosUriFactory::class]], + ['class' => DiactorosUriFactory::class, 'condition' => [DiactorosRequest::class, DiactorosUriFactory::class]], + ['class' => SlimUriFactory::class, 'condition' => [SlimRequest::class, SlimUriFactory::class]], + ], + HttpAsyncClient::class => [ + ['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, Promise::class, RequestFactory::class, [self::class, 'isPsr17FactoryInstalled']]], + ['class' => Guzzle7::class, 'condition' => Guzzle7::class], + ['class' => Guzzle6::class, 'condition' => Guzzle6::class], + ['class' => Curl::class, 'condition' => Curl::class], + ['class' => React::class, 'condition' => React::class], + ], + HttpClient::class => [ + ['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, RequestFactory::class, [self::class, 'isPsr17FactoryInstalled']]], + ['class' => Guzzle7::class, 'condition' => Guzzle7::class], + ['class' => Guzzle6::class, 'condition' => Guzzle6::class], + ['class' => Guzzle5::class, 'condition' => Guzzle5::class], + ['class' => Curl::class, 'condition' => Curl::class], + ['class' => Socket::class, 'condition' => Socket::class], + ['class' => Buzz::class, 'condition' => Buzz::class], + ['class' => React::class, 'condition' => React::class], + ['class' => Cake::class, 'condition' => Cake::class], + ['class' => Zend::class, 'condition' => Zend::class], + ['class' => Artax::class, 'condition' => Artax::class], + [ + 'class' => [self::class, 'buzzInstantiate'], + 'condition' => [\Buzz\Client\FileGetContents::class, \Buzz\Message\ResponseBuilder::class], + ], + ], + Psr18Client::class => [ + [ + 'class' => [self::class, 'symfonyPsr18Instantiate'], + 'condition' => [SymfonyPsr18::class, Psr17RequestFactory::class], + ], + [ + 'class' => GuzzleHttp::class, + 'condition' => [self::class, 'isGuzzleImplementingPsr18'], + ], + [ + 'class' => [self::class, 'buzzInstantiate'], + 'condition' => [\Buzz\Client\FileGetContents::class, \Buzz\Message\ResponseBuilder::class], + ], + ], + ]; + + /** + * {@inheritdoc} + */ + public static function getCandidates($type) + { + if (Psr18Client::class === $type) { + return self::getPsr18Candidates(); + } + + return self::$classes[$type] ?? []; + } + + /** + * @return array The return value is always an array with zero or more elements. Each + * element is an array with two keys ['class' => string, 'condition' => mixed]. + */ + private static function getPsr18Candidates() + { + $candidates = self::$classes[Psr18Client::class]; + + // HTTPlug 2.0 clients implements PSR18Client too. + foreach (self::$classes[HttpClient::class] as $c) { + if (!is_string($c['class'])) { + continue; + } + try { + if (ClassDiscovery::safeClassExists($c['class']) && is_subclass_of($c['class'], Psr18Client::class)) { + $candidates[] = $c; + } + } catch (\Throwable $e) { + trigger_error(sprintf('Got exception "%s (%s)" while checking if a PSR-18 Client is available', get_class($e), $e->getMessage()), E_USER_WARNING); + } + } + + return $candidates; + } + + public static function buzzInstantiate() + { + return new \Buzz\Client\FileGetContents(MessageFactoryDiscovery::find()); + } + + public static function symfonyPsr18Instantiate() + { + return new SymfonyPsr18(null, Psr17FactoryDiscovery::findResponseFactory(), Psr17FactoryDiscovery::findStreamFactory()); + } + + public static function isGuzzleImplementingPsr18() + { + return defined('GuzzleHttp\ClientInterface::MAJOR_VERSION'); + } + + /** + * Can be used as a condition. + * + * @return bool + */ + public static function isPsr17FactoryInstalled() + { + try { + Psr17FactoryDiscovery::findResponseFactory(); + } catch (NotFoundException $e) { + return false; + } catch (\Throwable $e) { + trigger_error(sprintf('Got exception "%s (%s)" while checking if a PSR-17 ResponseFactory is available', get_class($e), $e->getMessage()), E_USER_WARNING); + + return false; + } + + return true; + } +} diff --git a/Http/Discovery/Strategy/CommonPsr17ClassesStrategy.php b/Http/Discovery/Strategy/CommonPsr17ClassesStrategy.php new file mode 100644 index 0000000..fc26778 --- /dev/null +++ b/Http/Discovery/Strategy/CommonPsr17ClassesStrategy.php @@ -0,0 +1,105 @@ + + */ +final class CommonPsr17ClassesStrategy implements DiscoveryStrategy +{ + /** + * @var array + */ + private static $classes = [ + RequestFactoryInterface::class => [ + 'Phalcon\Http\Message\RequestFactory', + 'Nyholm\Psr7\Factory\Psr17Factory', + 'Zend\Diactoros\RequestFactory', + 'GuzzleHttp\Psr7\HttpFactory', + 'Http\Factory\Diactoros\RequestFactory', + 'Http\Factory\Guzzle\RequestFactory', + 'Http\Factory\Slim\RequestFactory', + 'Laminas\Diactoros\RequestFactory', + 'Slim\Psr7\Factory\RequestFactory', + ], + ResponseFactoryInterface::class => [ + 'Phalcon\Http\Message\ResponseFactory', + 'Nyholm\Psr7\Factory\Psr17Factory', + 'Zend\Diactoros\ResponseFactory', + 'GuzzleHttp\Psr7\HttpFactory', + 'Http\Factory\Diactoros\ResponseFactory', + 'Http\Factory\Guzzle\ResponseFactory', + 'Http\Factory\Slim\ResponseFactory', + 'Laminas\Diactoros\ResponseFactory', + 'Slim\Psr7\Factory\ResponseFactory', + ], + ServerRequestFactoryInterface::class => [ + 'Phalcon\Http\Message\ServerRequestFactory', + 'Nyholm\Psr7\Factory\Psr17Factory', + 'Zend\Diactoros\ServerRequestFactory', + 'GuzzleHttp\Psr7\HttpFactory', + 'Http\Factory\Diactoros\ServerRequestFactory', + 'Http\Factory\Guzzle\ServerRequestFactory', + 'Http\Factory\Slim\ServerRequestFactory', + 'Laminas\Diactoros\ServerRequestFactory', + 'Slim\Psr7\Factory\ServerRequestFactory', + ], + StreamFactoryInterface::class => [ + 'Phalcon\Http\Message\StreamFactory', + 'Nyholm\Psr7\Factory\Psr17Factory', + 'Zend\Diactoros\StreamFactory', + 'GuzzleHttp\Psr7\HttpFactory', + 'Http\Factory\Diactoros\StreamFactory', + 'Http\Factory\Guzzle\StreamFactory', + 'Http\Factory\Slim\StreamFactory', + 'Laminas\Diactoros\StreamFactory', + 'Slim\Psr7\Factory\StreamFactory', + ], + UploadedFileFactoryInterface::class => [ + 'Phalcon\Http\Message\UploadedFileFactory', + 'Nyholm\Psr7\Factory\Psr17Factory', + 'Zend\Diactoros\UploadedFileFactory', + 'GuzzleHttp\Psr7\HttpFactory', + 'Http\Factory\Diactoros\UploadedFileFactory', + 'Http\Factory\Guzzle\UploadedFileFactory', + 'Http\Factory\Slim\UploadedFileFactory', + 'Laminas\Diactoros\UploadedFileFactory', + 'Slim\Psr7\Factory\UploadedFileFactory', + ], + UriFactoryInterface::class => [ + 'Phalcon\Http\Message\UriFactory', + 'Nyholm\Psr7\Factory\Psr17Factory', + 'Zend\Diactoros\UriFactory', + 'GuzzleHttp\Psr7\HttpFactory', + 'Http\Factory\Diactoros\UriFactory', + 'Http\Factory\Guzzle\UriFactory', + 'Http\Factory\Slim\UriFactory', + 'Laminas\Diactoros\UriFactory', + 'Slim\Psr7\Factory\UriFactory', + ], + ]; + + /** + * {@inheritdoc} + */ + public static function getCandidates($type) + { + $candidates = []; + if (isset(self::$classes[$type])) { + foreach (self::$classes[$type] as $class) { + $candidates[] = ['class' => $class, 'condition' => [$class]]; + } + } + + return $candidates; + } +} diff --git a/Http/Discovery/Strategy/DiscoveryStrategy.php b/Http/Discovery/Strategy/DiscoveryStrategy.php new file mode 100644 index 0000000..1eadb14 --- /dev/null +++ b/Http/Discovery/Strategy/DiscoveryStrategy.php @@ -0,0 +1,23 @@ + + */ +interface DiscoveryStrategy +{ + /** + * Find a resource of a specific type. + * + * @param string $type + * + * @return array The return value is always an array with zero or more elements. Each + * element is an array with two keys ['class' => string, 'condition' => mixed]. + * + * @throws StrategyUnavailableException if we cannot use this strategy + */ + public static function getCandidates($type); +} diff --git a/Http/Discovery/Strategy/MockClientStrategy.php b/Http/Discovery/Strategy/MockClientStrategy.php new file mode 100644 index 0000000..0cee3f7 --- /dev/null +++ b/Http/Discovery/Strategy/MockClientStrategy.php @@ -0,0 +1,27 @@ + + */ +final class MockClientStrategy implements DiscoveryStrategy +{ + /** + * {@inheritdoc} + */ + public static function getCandidates($type) + { + if (is_a(HttpClient::class, $type, true) || is_a(HttpAsyncClient::class, $type, true)) { + return [['class' => Mock::class, 'condition' => Mock::class]]; + } + + return []; + } +} diff --git a/Http/Discovery/Strategy/PuliBetaStrategy.php b/Http/Discovery/Strategy/PuliBetaStrategy.php new file mode 100644 index 0000000..c1e1fb7 --- /dev/null +++ b/Http/Discovery/Strategy/PuliBetaStrategy.php @@ -0,0 +1,92 @@ + + * @author Márk Sági-Kazár + */ +class PuliBetaStrategy implements DiscoveryStrategy +{ + /** + * @var GeneratedPuliFactory + */ + protected static $puliFactory; + + /** + * @var Discovery + */ + protected static $puliDiscovery; + + /** + * @return GeneratedPuliFactory + * + * @throws PuliUnavailableException + */ + private static function getPuliFactory() + { + if (null === self::$puliFactory) { + if (!defined('PULI_FACTORY_CLASS')) { + throw new PuliUnavailableException('Puli Factory is not available'); + } + + $puliFactoryClass = PULI_FACTORY_CLASS; + + if (!ClassDiscovery::safeClassExists($puliFactoryClass)) { + throw new PuliUnavailableException('Puli Factory class does not exist'); + } + + self::$puliFactory = new $puliFactoryClass(); + } + + return self::$puliFactory; + } + + /** + * Returns the Puli discovery layer. + * + * @return Discovery + * + * @throws PuliUnavailableException + */ + private static function getPuliDiscovery() + { + if (!isset(self::$puliDiscovery)) { + $factory = self::getPuliFactory(); + $repository = $factory->createRepository(); + + self::$puliDiscovery = $factory->createDiscovery($repository); + } + + return self::$puliDiscovery; + } + + /** + * {@inheritdoc} + */ + public static function getCandidates($type) + { + $returnData = []; + $bindings = self::getPuliDiscovery()->findBindings($type); + + foreach ($bindings as $binding) { + $condition = true; + if ($binding->hasParameterValue('depends')) { + $condition = $binding->getParameterValue('depends'); + } + $returnData[] = ['class' => $binding->getClassName(), 'condition' => $condition]; + } + + return $returnData; + } +} diff --git a/Http/Discovery/StreamFactoryDiscovery.php b/Http/Discovery/StreamFactoryDiscovery.php new file mode 100644 index 0000000..e11c49a --- /dev/null +++ b/Http/Discovery/StreamFactoryDiscovery.php @@ -0,0 +1,34 @@ + + * + * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery. + */ +final class StreamFactoryDiscovery extends ClassDiscovery +{ + /** + * Finds a Stream Factory. + * + * @return StreamFactory + * + * @throws Exception\NotFoundException + */ + public static function find() + { + try { + $streamFactory = static::findOneByType(StreamFactory::class); + } catch (DiscoveryFailedException $e) { + throw new NotFoundException('No stream factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.', 0, $e); + } + + return static::instantiateClass($streamFactory); + } +} diff --git a/Http/Discovery/UriFactoryDiscovery.php b/Http/Discovery/UriFactoryDiscovery.php new file mode 100644 index 0000000..db3add2 --- /dev/null +++ b/Http/Discovery/UriFactoryDiscovery.php @@ -0,0 +1,34 @@ + + * + * @deprecated This will be removed in 2.0. Consider using Psr17FactoryDiscovery. + */ +final class UriFactoryDiscovery extends ClassDiscovery +{ + /** + * Finds a URI Factory. + * + * @return UriFactory + * + * @throws Exception\NotFoundException + */ + public static function find() + { + try { + $uriFactory = static::findOneByType(UriFactory::class); + } catch (DiscoveryFailedException $e) { + throw new NotFoundException('No uri factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.', 0, $e); + } + + return static::instantiateClass($uriFactory); + } +} diff --git a/Http/Httplug/Exception.php b/Http/Httplug/Exception.php new file mode 100644 index 0000000..4df164c --- /dev/null +++ b/Http/Httplug/Exception.php @@ -0,0 +1,14 @@ + + */ +interface Exception extends PsrClientException +{ +} diff --git a/Http/Httplug/Exception/HttpException.php b/Http/Httplug/Exception/HttpException.php new file mode 100644 index 0000000..6c2a007 --- /dev/null +++ b/Http/Httplug/Exception/HttpException.php @@ -0,0 +1,65 @@ + + */ +class HttpException extends RequestException +{ + /** + * @var ResponseInterface + */ + protected $response; + + /** + * @param string $message + */ + public function __construct( + $message, + RequestInterface $request, + ResponseInterface $response, + \Exception $previous = null + ) { + parent::__construct($message, $request, $previous); + + $this->response = $response; + $this->code = $response->getStatusCode(); + } + + /** + * Returns the response. + * + * @return ResponseInterface + */ + public function getResponse() + { + return $this->response; + } + + /** + * Factory method to create a new exception with a normalized error message. + */ + public static function create( + RequestInterface $request, + ResponseInterface $response, + \Exception $previous = null + ) { + $message = sprintf( + '[url] %s [http method] %s [status code] %s [reason phrase] %s', + $request->getRequestTarget(), + $request->getMethod(), + $response->getStatusCode(), + $response->getReasonPhrase() + ); + + return new static($message, $request, $response, $previous); + } +} diff --git a/Http/Httplug/Exception/NetworkException.php b/Http/Httplug/Exception/NetworkException.php new file mode 100644 index 0000000..9b4f1e8 --- /dev/null +++ b/Http/Httplug/Exception/NetworkException.php @@ -0,0 +1,28 @@ + + */ +class NetworkException extends TransferException implements PsrNetworkException +{ + use RequestAwareTrait; + + /** + * @param string $message + */ + public function __construct($message, RequestInterface $request, \Exception $previous = null) + { + $this->setRequest($request); + + parent::__construct($message, 0, $previous); + } +} diff --git a/Http/Httplug/Exception/RequestAwareTrait.php b/Http/Httplug/Exception/RequestAwareTrait.php new file mode 100644 index 0000000..71b4bb8 --- /dev/null +++ b/Http/Httplug/Exception/RequestAwareTrait.php @@ -0,0 +1,26 @@ +request = $request; + } + + /** + * {@inheritdoc} + */ + public function getRequest(): RequestInterface + { + return $this->request; + } +} diff --git a/Http/Httplug/Exception/RequestException.php b/Http/Httplug/Exception/RequestException.php new file mode 100644 index 0000000..f6c60ce --- /dev/null +++ b/Http/Httplug/Exception/RequestException.php @@ -0,0 +1,29 @@ + + */ +class RequestException extends TransferException implements PsrRequestException +{ + use RequestAwareTrait; + + /** + * @param string $message + */ + public function __construct($message, RequestInterface $request, \Exception $previous = null) + { + $this->setRequest($request); + + parent::__construct($message, 0, $previous); + } +} diff --git a/Http/Httplug/Exception/TransferException.php b/Http/Httplug/Exception/TransferException.php new file mode 100644 index 0000000..a858cf5 --- /dev/null +++ b/Http/Httplug/Exception/TransferException.php @@ -0,0 +1,14 @@ + + */ +class TransferException extends \RuntimeException implements Exception +{ +} diff --git a/Http/Httplug/HttpAsyncClient.php b/Http/Httplug/HttpAsyncClient.php new file mode 100644 index 0000000..c3b9d61 --- /dev/null +++ b/Http/Httplug/HttpAsyncClient.php @@ -0,0 +1,25 @@ + + */ +interface HttpAsyncClient +{ + /** + * Sends a PSR-7 request in an asynchronous way. + * + * Exceptions related to processing the request are available from the returned Promise. + * + * @return Promise resolves a PSR-7 Response or fails with an Http\Client\Exception + * + * @throws \Exception If processing the request is impossible (eg. bad configuration). + */ + public function sendAsyncRequest(RequestInterface $request); +} diff --git a/Http/Httplug/HttpClient.php b/Http/Httplug/HttpClient.php new file mode 100644 index 0000000..4442bd0 --- /dev/null +++ b/Http/Httplug/HttpClient.php @@ -0,0 +1,15 @@ + +Copyright (c) 2015 PHP HTTP Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Http/Httplug/Promise/HttpFulfilledPromise.php b/Http/Httplug/Promise/HttpFulfilledPromise.php new file mode 100644 index 0000000..1ad32cd --- /dev/null +++ b/Http/Httplug/Promise/HttpFulfilledPromise.php @@ -0,0 +1,54 @@ +response = $response; + } + + /** + * {@inheritdoc} + */ + public function then(callable $onFulfilled = null, callable $onRejected = null) + { + if (null === $onFulfilled) { + return $this; + } + + try { + return new self($onFulfilled($this->response)); + } catch (Exception $e) { + return new HttpRejectedPromise($e); + } + } + + /** + * {@inheritdoc} + */ + public function getState() + { + return Promise::FULFILLED; + } + + /** + * {@inheritdoc} + */ + public function wait($unwrap = true) + { + if ($unwrap) { + return $this->response; + } + } +} diff --git a/Http/Httplug/Promise/HttpRejectedPromise.php b/Http/Httplug/Promise/HttpRejectedPromise.php new file mode 100644 index 0000000..624cc8a --- /dev/null +++ b/Http/Httplug/Promise/HttpRejectedPromise.php @@ -0,0 +1,58 @@ +exception = $exception; + } + + /** + * {@inheritdoc} + */ + public function then(callable $onFulfilled = null, callable $onRejected = null) + { + if (null === $onRejected) { + return $this; + } + + try { + $result = $onRejected($this->exception); + if ($result instanceof Promise) { + return $result; + } + + return new HttpFulfilledPromise($result); + } catch (Exception $e) { + return new self($e); + } + } + + /** + * {@inheritdoc} + */ + public function getState() + { + return Promise::REJECTED; + } + + /** + * {@inheritdoc} + */ + public function wait($unwrap = true) + { + if ($unwrap) { + throw $this->exception; + } + } +} diff --git a/Http/Message/LICENSE b/Http/Message/LICENSE new file mode 100644 index 0000000..4558d6f --- /dev/null +++ b/Http/Message/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015-2016 PHP HTTP Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Http/Message/MessageFactory.php b/Http/Message/MessageFactory.php new file mode 100644 index 0000000..965aaa8 --- /dev/null +++ b/Http/Message/MessageFactory.php @@ -0,0 +1,12 @@ + + */ +interface MessageFactory extends RequestFactory, ResponseFactory +{ +} diff --git a/Http/Message/RequestFactory.php b/Http/Message/RequestFactory.php new file mode 100644 index 0000000..624e82f --- /dev/null +++ b/Http/Message/RequestFactory.php @@ -0,0 +1,34 @@ + + */ +interface RequestFactory +{ + /** + * Creates a new PSR-7 request. + * + * @param string $method + * @param string|UriInterface $uri + * @param array $headers + * @param resource|string|StreamInterface|null $body + * @param string $protocolVersion + * + * @return RequestInterface + */ + public function createRequest( + $method, + $uri, + array $headers = [], + $body = null, + $protocolVersion = '1.1' + ); +} diff --git a/Http/Message/ResponseFactory.php b/Http/Message/ResponseFactory.php new file mode 100644 index 0000000..2411ed3 --- /dev/null +++ b/Http/Message/ResponseFactory.php @@ -0,0 +1,35 @@ + + */ +interface ResponseFactory +{ + /** + * Creates a new PSR-7 response. + * + * @param int $statusCode + * @param string|null $reasonPhrase + * @param array $headers + * @param resource|string|StreamInterface|null $body + * @param string $protocolVersion + * + * @return ResponseInterface + */ + public function createResponse( + $statusCode = 200, + $reasonPhrase = null, + array $headers = [], + $body = null, + $protocolVersion = '1.1' + ); +} diff --git a/Http/Message/StreamFactory.php b/Http/Message/StreamFactory.php new file mode 100644 index 0000000..e151389 --- /dev/null +++ b/Http/Message/StreamFactory.php @@ -0,0 +1,25 @@ + + */ +interface StreamFactory +{ + /** + * Creates a new PSR-7 stream. + * + * @param string|resource|StreamInterface|null $body + * + * @return StreamInterface + * + * @throws \InvalidArgumentException if the stream body is invalid + * @throws \RuntimeException if creating the stream from $body fails + */ + public function createStream($body = null); +} diff --git a/Http/Message/UriFactory.php b/Http/Message/UriFactory.php new file mode 100644 index 0000000..e8d8f90 --- /dev/null +++ b/Http/Message/UriFactory.php @@ -0,0 +1,24 @@ + + */ +interface UriFactory +{ + /** + * Creates an PSR-7 URI. + * + * @param string|UriInterface $uri + * + * @return UriInterface + * + * @throws \InvalidArgumentException if the $uri argument can not be converted into a valid URI + */ + public function createUri($uri); +} diff --git a/Psr/Http/Client/ClientExceptionInterface.php b/Psr/Http/Client/ClientExceptionInterface.php new file mode 100644 index 0000000..aa0b9cf --- /dev/null +++ b/Psr/Http/Client/ClientExceptionInterface.php @@ -0,0 +1,10 @@ +getHeaders() as $name => $values) { + * echo $name . ": " . implode(", ", $values); + * } + * + * // Emit headers iteratively: + * foreach ($message->getHeaders() as $name => $values) { + * foreach ($values as $value) { + * header(sprintf('%s: %s', $name, $value), false); + * } + * } + * + * While header names are not case-sensitive, getHeaders() will preserve the + * exact case in which headers were originally specified. + * + * @return string[][] Returns an associative array of the message's headers. Each + * key MUST be a header name, and each value MUST be an array of strings + * for that header. + */ + public function getHeaders(); + + /** + * Checks if a header exists by the given case-insensitive name. + * + * @param string $name Case-insensitive header field name. + * @return bool Returns true if any header names match the given header + * name using a case-insensitive string comparison. Returns false if + * no matching header name is found in the message. + */ + public function hasHeader($name); + + /** + * Retrieves a message header value by the given case-insensitive name. + * + * This method returns an array of all the header values of the given + * case-insensitive header name. + * + * If the header does not appear in the message, this method MUST return an + * empty array. + * + * @param string $name Case-insensitive header field name. + * @return string[] An array of string values as provided for the given + * header. If the header does not appear in the message, this method MUST + * return an empty array. + */ + public function getHeader($name); + + /** + * Retrieves a comma-separated string of the values for a single header. + * + * This method returns all of the header values of the given + * case-insensitive header name as a string concatenated together using + * a comma. + * + * NOTE: Not all header values may be appropriately represented using + * comma concatenation. For such headers, use getHeader() instead + * and supply your own delimiter when concatenating. + * + * If the header does not appear in the message, this method MUST return + * an empty string. + * + * @param string $name Case-insensitive header field name. + * @return string A string of values as provided for the given header + * concatenated together using a comma. If the header does not appear in + * the message, this method MUST return an empty string. + */ + public function getHeaderLine($name); + + /** + * Return an instance with the provided value replacing the specified header. + * + * While header names are case-insensitive, the casing of the header will + * be preserved by this function, and returned from getHeaders(). + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that has the + * new and/or updated header and value. + * + * @param string $name Case-insensitive header field name. + * @param string|string[] $value Header value(s). + * @return static + * @throws \InvalidArgumentException for invalid header names or values. + */ + public function withHeader($name, $value); + + /** + * Return an instance with the specified header appended with the given value. + * + * Existing values for the specified header will be maintained. The new + * value(s) will be appended to the existing list. If the header did not + * exist previously, it will be added. + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that has the + * new header and/or value. + * + * @param string $name Case-insensitive header field name to add. + * @param string|string[] $value Header value(s). + * @return static + * @throws \InvalidArgumentException for invalid header names or values. + */ + public function withAddedHeader($name, $value); + + /** + * Return an instance without the specified header. + * + * Header resolution MUST be done without case-sensitivity. + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that removes + * the named header. + * + * @param string $name Case-insensitive header field name to remove. + * @return static + */ + public function withoutHeader($name); + + /** + * Gets the body of the message. + * + * @return StreamInterface Returns the body as a stream. + */ + public function getBody(); + + /** + * Return an instance with the specified message body. + * + * The body MUST be a StreamInterface object. + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return a new instance that has the + * new body stream. + * + * @param StreamInterface $body Body. + * @return static + * @throws \InvalidArgumentException When the body is not valid. + */ + public function withBody(StreamInterface $body); +} diff --git a/Psr/Http/Message/RequestInterface.php b/Psr/Http/Message/RequestInterface.php new file mode 100644 index 0000000..a96d4fd --- /dev/null +++ b/Psr/Http/Message/RequestInterface.php @@ -0,0 +1,129 @@ +getQuery()` + * or from the `QUERY_STRING` server param. + * + * @return array + */ + public function getQueryParams(); + + /** + * Return an instance with the specified query string arguments. + * + * These values SHOULD remain immutable over the course of the incoming + * request. They MAY be injected during instantiation, such as from PHP's + * $_GET superglobal, or MAY be derived from some other value such as the + * URI. In cases where the arguments are parsed from the URI, the data + * MUST be compatible with what PHP's parse_str() would return for + * purposes of how duplicate query parameters are handled, and how nested + * sets are handled. + * + * Setting query string arguments MUST NOT change the URI stored by the + * request, nor the values in the server params. + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that has the + * updated query string arguments. + * + * @param array $query Array of query string arguments, typically from + * $_GET. + * @return static + */ + public function withQueryParams(array $query); + + /** + * Retrieve normalized file upload data. + * + * This method returns upload metadata in a normalized tree, with each leaf + * an instance of Psr\Http\Message\UploadedFileInterface. + * + * These values MAY be prepared from $_FILES or the message body during + * instantiation, or MAY be injected via withUploadedFiles(). + * + * @return array An array tree of UploadedFileInterface instances; an empty + * array MUST be returned if no data is present. + */ + public function getUploadedFiles(); + + /** + * Create a new instance with the specified uploaded files. + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that has the + * updated body parameters. + * + * @param array $uploadedFiles An array tree of UploadedFileInterface instances. + * @return static + * @throws \InvalidArgumentException if an invalid structure is provided. + */ + public function withUploadedFiles(array $uploadedFiles); + + /** + * Retrieve any parameters provided in the request body. + * + * If the request Content-Type is either application/x-www-form-urlencoded + * or multipart/form-data, and the request method is POST, this method MUST + * return the contents of $_POST. + * + * Otherwise, this method may return any results of deserializing + * the request body content; as parsing returns structured content, the + * potential types MUST be arrays or objects only. A null value indicates + * the absence of body content. + * + * @return null|array|object The deserialized body parameters, if any. + * These will typically be an array or object. + */ + public function getParsedBody(); + + /** + * Return an instance with the specified body parameters. + * + * These MAY be injected during instantiation. + * + * If the request Content-Type is either application/x-www-form-urlencoded + * or multipart/form-data, and the request method is POST, use this method + * ONLY to inject the contents of $_POST. + * + * The data IS NOT REQUIRED to come from $_POST, but MUST be the results of + * deserializing the request body content. Deserialization/parsing returns + * structured data, and, as such, this method ONLY accepts arrays or objects, + * or a null value if nothing was available to parse. + * + * As an example, if content negotiation determines that the request data + * is a JSON payload, this method could be used to create a request + * instance with the deserialized parameters. + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that has the + * updated body parameters. + * + * @param null|array|object $data The deserialized body data. This will + * typically be in an array or object. + * @return static + * @throws \InvalidArgumentException if an unsupported argument type is + * provided. + */ + public function withParsedBody($data); + + /** + * Retrieve attributes derived from the request. + * + * The request "attributes" may be used to allow injection of any + * parameters derived from the request: e.g., the results of path + * match operations; the results of decrypting cookies; the results of + * deserializing non-form-encoded message bodies; etc. Attributes + * will be application and request specific, and CAN be mutable. + * + * @return array Attributes derived from the request. + */ + public function getAttributes(); + + /** + * Retrieve a single derived request attribute. + * + * Retrieves a single derived request attribute as described in + * getAttributes(). If the attribute has not been previously set, returns + * the default value as provided. + * + * This method obviates the need for a hasAttribute() method, as it allows + * specifying a default value to return if the attribute is not found. + * + * @see getAttributes() + * @param string $name The attribute name. + * @param mixed $default Default value to return if the attribute does not exist. + * @return mixed + */ + public function getAttribute($name, $default = null); + + /** + * Return an instance with the specified derived request attribute. + * + * This method allows setting a single derived request attribute as + * described in getAttributes(). + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that has the + * updated attribute. + * + * @see getAttributes() + * @param string $name The attribute name. + * @param mixed $value The value of the attribute. + * @return static + */ + public function withAttribute($name, $value); + + /** + * Return an instance that removes the specified derived request attribute. + * + * This method allows removing a single derived request attribute as + * described in getAttributes(). + * + * This method MUST be implemented in such a way as to retain the + * immutability of the message, and MUST return an instance that removes + * the attribute. + * + * @see getAttributes() + * @param string $name The attribute name. + * @return static + */ + public function withoutAttribute($name); +} diff --git a/Psr/Http/Message/StreamInterface.php b/Psr/Http/Message/StreamInterface.php new file mode 100644 index 0000000..f68f391 --- /dev/null +++ b/Psr/Http/Message/StreamInterface.php @@ -0,0 +1,158 @@ + + * [user-info@]host[:port] + * + * + * If the port component is not set or is the standard port for the current + * scheme, it SHOULD NOT be included. + * + * @see https://tools.ietf.org/html/rfc3986#section-3.2 + * @return string The URI authority, in "[user-info@]host[:port]" format. + */ + public function getAuthority(); + + /** + * Retrieve the user information component of the URI. + * + * If no user information is present, this method MUST return an empty + * string. + * + * If a user is present in the URI, this will return that value; + * additionally, if the password is also present, it will be appended to the + * user value, with a colon (":") separating the values. + * + * The trailing "@" character is not part of the user information and MUST + * NOT be added. + * + * @return string The URI user information, in "username[:password]" format. + */ + public function getUserInfo(); + + /** + * Retrieve the host component of the URI. + * + * If no host is present, this method MUST return an empty string. + * + * The value returned MUST be normalized to lowercase, per RFC 3986 + * Section 3.2.2. + * + * @see http://tools.ietf.org/html/rfc3986#section-3.2.2 + * @return string The URI host. + */ + public function getHost(); + + /** + * Retrieve the port component of the URI. + * + * If a port is present, and it is non-standard for the current scheme, + * this method MUST return it as an integer. If the port is the standard port + * used with the current scheme, this method SHOULD return null. + * + * If no port is present, and no scheme is present, this method MUST return + * a null value. + * + * If no port is present, but a scheme is present, this method MAY return + * the standard port for that scheme, but SHOULD return null. + * + * @return null|int The URI port. + */ + public function getPort(); + + /** + * Retrieve the path component of the URI. + * + * The path can either be empty or absolute (starting with a slash) or + * rootless (not starting with a slash). Implementations MUST support all + * three syntaxes. + * + * Normally, the empty path "" and absolute path "/" are considered equal as + * defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically + * do this normalization because in contexts with a trimmed base path, e.g. + * the front controller, this difference becomes significant. It's the task + * of the user to handle both "" and "/". + * + * The value returned MUST be percent-encoded, but MUST NOT double-encode + * any characters. To determine what characters to encode, please refer to + * RFC 3986, Sections 2 and 3.3. + * + * As an example, if the value should include a slash ("/") not intended as + * delimiter between path segments, that value MUST be passed in encoded + * form (e.g., "%2F") to the instance. + * + * @see https://tools.ietf.org/html/rfc3986#section-2 + * @see https://tools.ietf.org/html/rfc3986#section-3.3 + * @return string The URI path. + */ + public function getPath(); + + /** + * Retrieve the query string of the URI. + * + * If no query string is present, this method MUST return an empty string. + * + * The leading "?" character is not part of the query and MUST NOT be + * added. + * + * The value returned MUST be percent-encoded, but MUST NOT double-encode + * any characters. To determine what characters to encode, please refer to + * RFC 3986, Sections 2 and 3.4. + * + * As an example, if a value in a key/value pair of the query string should + * include an ampersand ("&") not intended as a delimiter between values, + * that value MUST be passed in encoded form (e.g., "%26") to the instance. + * + * @see https://tools.ietf.org/html/rfc3986#section-2 + * @see https://tools.ietf.org/html/rfc3986#section-3.4 + * @return string The URI query string. + */ + public function getQuery(); + + /** + * Retrieve the fragment component of the URI. + * + * If no fragment is present, this method MUST return an empty string. + * + * The leading "#" character is not part of the fragment and MUST NOT be + * added. + * + * The value returned MUST be percent-encoded, but MUST NOT double-encode + * any characters. To determine what characters to encode, please refer to + * RFC 3986, Sections 2 and 3.5. + * + * @see https://tools.ietf.org/html/rfc3986#section-2 + * @see https://tools.ietf.org/html/rfc3986#section-3.5 + * @return string The URI fragment. + */ + public function getFragment(); + + /** + * Return an instance with the specified scheme. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified scheme. + * + * Implementations MUST support the schemes "http" and "https" case + * insensitively, and MAY accommodate other schemes if required. + * + * An empty scheme is equivalent to removing the scheme. + * + * @param string $scheme The scheme to use with the new instance. + * @return static A new instance with the specified scheme. + * @throws \InvalidArgumentException for invalid or unsupported schemes. + */ + public function withScheme($scheme); + + /** + * Return an instance with the specified user information. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified user information. + * + * Password is optional, but the user information MUST include the + * user; an empty string for the user is equivalent to removing user + * information. + * + * @param string $user The user name to use for authority. + * @param null|string $password The password associated with $user. + * @return static A new instance with the specified user information. + */ + public function withUserInfo($user, $password = null); + + /** + * Return an instance with the specified host. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified host. + * + * An empty host value is equivalent to removing the host. + * + * @param string $host The hostname to use with the new instance. + * @return static A new instance with the specified host. + * @throws \InvalidArgumentException for invalid hostnames. + */ + public function withHost($host); + + /** + * Return an instance with the specified port. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified port. + * + * Implementations MUST raise an exception for ports outside the + * established TCP and UDP port ranges. + * + * A null value provided for the port is equivalent to removing the port + * information. + * + * @param null|int $port The port to use with the new instance; a null value + * removes the port information. + * @return static A new instance with the specified port. + * @throws \InvalidArgumentException for invalid ports. + */ + public function withPort($port); + + /** + * Return an instance with the specified path. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified path. + * + * The path can either be empty or absolute (starting with a slash) or + * rootless (not starting with a slash). Implementations MUST support all + * three syntaxes. + * + * If the path is intended to be domain-relative rather than path relative then + * it must begin with a slash ("/"). Paths not starting with a slash ("/") + * are assumed to be relative to some base path known to the application or + * consumer. + * + * Users can provide both encoded and decoded path characters. + * Implementations ensure the correct encoding as outlined in getPath(). + * + * @param string $path The path to use with the new instance. + * @return static A new instance with the specified path. + * @throws \InvalidArgumentException for invalid paths. + */ + public function withPath($path); + + /** + * Return an instance with the specified query string. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified query string. + * + * Users can provide both encoded and decoded query characters. + * Implementations ensure the correct encoding as outlined in getQuery(). + * + * An empty query string value is equivalent to removing the query string. + * + * @param string $query The query string to use with the new instance. + * @return static A new instance with the specified query string. + * @throws \InvalidArgumentException for invalid query strings. + */ + public function withQuery($query); + + /** + * Return an instance with the specified URI fragment. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified URI fragment. + * + * Users can provide both encoded and decoded fragment characters. + * Implementations ensure the correct encoding as outlined in getFragment(). + * + * An empty fragment value is equivalent to removing the fragment. + * + * @param string $fragment The fragment to use with the new instance. + * @return static A new instance with the specified fragment. + */ + public function withFragment($fragment); + + /** + * Return the string representation as a URI reference. + * + * Depending on which components of the URI are present, the resulting + * string is either a full URI or relative reference according to RFC 3986, + * Section 4.1. The method concatenates the various components of the URI, + * using the appropriate delimiters: + * + * - If a scheme is present, it MUST be suffixed by ":". + * - If an authority is present, it MUST be prefixed by "//". + * - The path can be concatenated without delimiters. But there are two + * cases where the path has to be adjusted to make the URI reference + * valid as PHP does not allow to throw an exception in __toString(): + * - If the path is rootless and an authority is present, the path MUST + * be prefixed by "/". + * - If the path is starting with more than one "/" and no authority is + * present, the starting slashes MUST be reduced to one. + * - If a query is present, it MUST be prefixed by "?". + * - If a fragment is present, it MUST be prefixed by "#". + * + * @see http://tools.ietf.org/html/rfc3986#section-4.1 + * @return string + */ + public function __toString(); +}