Skip to content

Commit

Permalink
Add SearchTemplate Endpont
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Mar 24, 2014
1 parent a3a66b7 commit 78cdf38
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,34 @@ public function search($params = array())
}


/**
* $params['index'] = (list) A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices
* ['type'] = (list) A comma-separated list of document types to search; leave empty to perform the operation on all types
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function searchTemplate($params = array())
{
$index = $this->extractArgument($params, 'index');
$type = $this->extractArgument($params, 'type');
$body = $this->extractArgument($params, 'body');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Search $endpoint */
$endpoint = $endpointBuilder('SearchTemplate');
$endpoint->setIndex($index)
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}


/**
* $params['scroll_id'] = (string) The scroll ID for scrolled search
* ['scroll'] = (duration) Specify how long a consistent view of the index should be maintained for scrolled search
Expand Down
81 changes: 81 additions & 0 deletions src/Elasticsearch/Endpoints/SearchTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* User: zach
* Date: 3/24/14
* Time: 5:09 PM
*/

namespace Elasticsearch\Endpoints;

use Elasticsearch\Common\Exceptions\InvalidArgumentException;
use Elasticsearch\Endpoints\AbstractEndpoint;
use Elasticsearch\Common\Exceptions;

/**
* Class SearchTemplate
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/

class SearchTemplate extends AbstractEndpoint
{
/**
* @param array $body
*
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
* @return $this
*/
public function setBody($body)
{
if (isset($body) !== true) {
return $this;
}

$this->body = $body;
return $this;
}



/**
* @return string
*/
protected function getURI()
{
$index = $this->index;
$type = $this->type;
$uri = "/_search/template";

if (isset($index) === true && isset($type) === true) {
$uri = "/$index/$type/_search/template";
} elseif (isset($index) === true) {
$uri = "/$index/_search/template";
} elseif (isset($type) === true) {
$uri = "/_all/$type/_search/template";
}

return $uri;
}


/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array();
}


/**
* @return string
*/
protected function getMethod()
{
return 'GET';
}
}

0 comments on commit 78cdf38

Please sign in to comment.