Skip to content

Commit

Permalink
Add MPercolate Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Feb 11, 2014
1 parent c2b7b43 commit 90158a8
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,38 @@ public function percolate($params)
}


/**
* $params['index'] = (string) Default index for items which don't provide one
* ['type'] = (string) Default document type for items which don't provide one
* ['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.
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function mpercolate($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\MPercolate $endpoint */
$endpoint = $endpointBuilder('MPercolate');
$endpoint->setIndex($index)
->setType($type)
->setBody($body);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}


/**
* $params['id'] = (string) The document ID (Required)
* ['index'] = (string) The name of the index (Required)
Expand Down
84 changes: 84 additions & 0 deletions src/Elasticsearch/Endpoints/MPercolate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* User: zach
* Date: 05/31/2013
* Time: 16:47:11 pm
*/

namespace Elasticsearch\Endpoints;

use Elasticsearch\Endpoints\AbstractEndpoint;
use Elasticsearch\Common\Exceptions;
use Elasticsearch\Serializers\SerializerInterface;
use Elasticsearch\Transport;

/**
* Class MPercolate
* @package Elasticsearch\Endpoints
*/
class MPercolate extends AbstractEndpoint implements BulkEndpointInterface
{

/**
* @param Transport $transport
* @param SerializerInterface $serializer
*/
public function __construct(Transport $transport, SerializerInterface $serializer)
{
$this->serializer = $serializer;
parent::__construct($transport);
}


/**
* @param string|array $body
*
* @return $this
*/
public function setBody($body)
{
if (isset($body) !== true) {
return $this;
}

if (is_array($body) === true) {
$bulkBody = "";
foreach ($body as $item) {
$bulkBody .= $this->serializer->serialize($item)."\n";
}
$body = $bulkBody;
}

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

/**
* @return string
*/
protected function getURI()
{
return $this->getOptionalURI('_mpercolate');

}

/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array(
'ignore_unavailable',
'allow_no_indices',
'expand_wildcards',
);
}

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

0 comments on commit 90158a8

Please sign in to comment.