Skip to content

Commit 6650ae8

Browse files
author
Raymond Julin
committed
Added support for client->request() for generic calls that are yet not supported (put mapping for instance)
1 parent 4a41d5f commit 6650ae8

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

ElasticSearchClient.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ public function get($id, $verbose=false) {
6464
? $response
6565
: $response['_source'];
6666
}
67+
68+
/**
69+
* Perform a request
70+
*
71+
* @return array
72+
* @param mixed $id Optional
73+
*/
74+
public function request($path, $method, $payload, $verbose=false) {
75+
$path = array_merge((array) $this->type, (array) $path);
76+
77+
$response = $this->transport->request($path, $method, $payload);
78+
return ($verbose)
79+
? $response
80+
: $response['_source'];
81+
}
6782

6883
/**
6984
* Index a new document or update it if existing

lib/transport/ElasticSearchTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ abstract class ElasticSearchTransport {
44
protected $index, $type;
55

66
abstract public function index($document, $id=false);
7-
abstract public function request($path);
7+
abstract public function request($path, $method="GET", $payload=false);
88
abstract public function delete($id=false);
99
abstract public function search($query);
1010

lib/transport/ElasticSearchTransportHTTP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ public function deleteByQuery($query) {
155155
* @return array
156156
* @param mixed $id Optional
157157
*/
158-
public function request($path, $method="GET") {
158+
public function request($path, $method="GET", $payload=false) {
159159
$url = $this->buildUrl($path);
160160
try {
161-
$result = $this->call($url, $method);
161+
$result = $this->call($url, $method, $payload);
162162
}
163163
catch (Exception $e) {
164164
throw $e;

lib/transport/ElasticSearchTransportMemcached.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function deleteByQuery($query) {
9595
* @return array
9696
* @param mixed $id Optional
9797
*/
98-
public function request($path, $method="GET") {
98+
public function request($path, $method="GET", $payload=false) {
9999
$url = $this->buildUrl($path);
100100
switch ($method) {
101101
case 'GET':

0 commit comments

Comments
 (0)