diff --git a/src/Elasticsearch/Client.php b/src/Elasticsearch/Client.php index 63e09ec03..c73d3e2ce 100644 --- a/src/Elasticsearch/Client.php +++ b/src/Elasticsearch/Client.php @@ -1260,6 +1260,74 @@ public function putScript($params) return $response['data']; } + /** + * $params['id'] = (string) The search template ID (Required) + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function getTemplate($params) + { + $id = $this->extractArgument($params, 'id'); + + /** @var callback $endpointBuilder */ + $endpointBuilder = $this->dicEndpoints; + + /** @var \Elasticsearch\Endpoints\Template\Get $endpoint */ + $endpoint = $endpointBuilder('Template\Get'); + $endpoint->setID($id); + $endpoint->setParams($params); + $response = $endpoint->performRequest(); + return $response['data']; + } + + /** + * $params['id'] = (string) The search template ID (Required) + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function deleteTemplate($params) + { + $id = $this->extractArgument($params, 'id'); + + /** @var callback $endpointBuilder */ + $endpointBuilder = $this->dicEndpoints; + + /** @var \Elasticsearch\Endpoints\Template\Delete $endpoint */ + $endpoint = $endpointBuilder('Template\Delete'); + $endpoint->setID($id); + $endpoint->setParams($params); + $response = $endpoint->performRequest(); + return $response['data']; + } + + /** + * $params['id'] = (string) The search template ID (Required) + * + * @param $params array Associative array of parameters + * + * @return array + */ + public function putTemplate($params) + { + $id = $this->extractArgument($params, 'id'); + $body = $this->extractArgument($params, 'body'); + + /** @var callback $endpointBuilder */ + $endpointBuilder = $this->dicEndpoints; + + /** @var \Elasticsearch\Endpoints\Template\Put $endpoint */ + $endpoint = $endpointBuilder('Template\Put'); + $endpoint->setID($id) + ->setBody($body); + $endpoint->setParams($params); + $response = $endpoint->performRequest(); + return $response['data']; + } + /** diff --git a/src/Elasticsearch/Endpoints/Template/Delete.php b/src/Elasticsearch/Endpoints/Template/Delete.php new file mode 100644 index 000000000..a384505a9 --- /dev/null +++ b/src/Elasticsearch/Endpoints/Template/Delete.php @@ -0,0 +1,60 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elasticsearch.org + */ + +class Delete extends AbstractEndpoint +{ + + /** + * @throws \Elasticsearch\Common\Exceptions\RuntimeException + * @return string + */ + protected function getURI() + { + if (isset($this->id) !== true) { + throw new Exceptions\RuntimeException( + 'id is required for Delete' + ); + } + $templateId = $this->id; + $uri = "/_search/template/$templateId"; + + return $uri; + } + + + /** + * @return string[] + */ + protected function getParamWhitelist() + { + return array(); + } + + + /** + * @return string + */ + protected function getMethod() + { + return 'DELETE'; + } +} \ No newline at end of file diff --git a/src/Elasticsearch/Endpoints/Template/Get.php b/src/Elasticsearch/Endpoints/Template/Get.php new file mode 100644 index 000000000..dfea20815 --- /dev/null +++ b/src/Elasticsearch/Endpoints/Template/Get.php @@ -0,0 +1,60 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elasticsearch.org + */ + +class Get extends AbstractEndpoint +{ + + /** + * @throws \Elasticsearch\Common\Exceptions\RuntimeException + * @return string + */ + protected function getURI() + { + if (isset($this->id) !== true) { + throw new Exceptions\RuntimeException( + 'id is required for Get' + ); + } + $templateId = $this->id; + $uri = "/_search/template/$templateId"; + + return $uri; + } + + + /** + * @return string[] + */ + protected function getParamWhitelist() + { + return array(); + } + + + /** + * @return string + */ + protected function getMethod() + { + return 'GET'; + } +} \ No newline at end of file diff --git a/src/Elasticsearch/Endpoints/Template/Put.php b/src/Elasticsearch/Endpoints/Template/Put.php new file mode 100644 index 000000000..eb205b133 --- /dev/null +++ b/src/Elasticsearch/Endpoints/Template/Put.php @@ -0,0 +1,77 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 + * @link http://elasticsearch.org + */ + +class Put extends AbstractEndpoint +{ + + /** + * @param array $body + * + * @return $this + */ + public function setBody($body) + { + if (isset($body) !== true) { + return $this; + } + + $this->body = $body; + return $this; + } + + + /** + * @throws \Elasticsearch\Common\Exceptions\RuntimeException + * @return string + */ + protected function getURI() + { + if (isset($this->id) !== true) { + throw new Exceptions\RuntimeException( + 'id is required for Put' + ); + } + + $templateId = $this->id; + $uri = "/_search/template/$templateId"; + + return $uri; + } + + + /** + * @return string[] + */ + protected function getParamWhitelist() + { + return array(); + } + + + /** + * @return string + */ + protected function getMethod() + { + return 'PUT'; + } +} \ No newline at end of file