Skip to content

Commit acbc76d

Browse files
committed
Fix 843,846,add User-Agent + RankEval + ScriptsPainlessExecute
1 parent 5d5f418 commit acbc76d

23 files changed

+290
-18
lines changed

src/Elasticsearch/Client.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
*/
3535
class Client
3636
{
37+
const VERSION = '6.5.1';
38+
3739
/**
3840
* @var Transport
3941
*/
@@ -155,6 +157,39 @@ public function ping($params = [])
155157
return true;
156158
}
157159

160+
/**
161+
* $params['body'] = (string) The ranking evaluation search definition, including
162+
* search requests, document ratings and ranking metric definition (Required)
163+
* ['index'] = (list) A comma-separated list of index names to search; use `_all` or
164+
* empty string to perform the operation on all indices
165+
* ['ignore_unavailable'] = (boolean) Whether specified concrete indices should be
166+
* ignored when unavailable (missing or closed)
167+
* ['allow_no_indices'] = (boolean) Whether to ignore if a wildcard indices expression
168+
* resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
169+
* ['expand_wildcards'] = (enum) Whether to expand wildcard expression to concrete indices that are open,
170+
* closed or both.
171+
*
172+
* @return callable|array
173+
*/
174+
public function rankEval(array $params)
175+
{
176+
$body = $this->extractArgument($params, 'body');
177+
$index = $this->extractArgument($params, 'index');
178+
/**
179+
* @var callable $endpointBuilder
180+
*/
181+
$endpointBuilder = $this->endpoints;
182+
/**
183+
* @var \Elasticsearch\Endpoints\RankEval $endpoint
184+
*/
185+
$endpoint = $endpointBuilder('RankEval');
186+
$endpoint->setBody($body)
187+
->setIndex($index);
188+
$endpoint->setParams($params);
189+
190+
return $this->performRequest($endpoint);
191+
}
192+
158193
/**
159194
* $params['id'] = (string) The document ID (Required)
160195
* ['index'] = (string) The name of the index (Required)
@@ -1011,6 +1046,27 @@ public function scroll($params = array())
10111046
return $this->performRequest($endpoint);
10121047
}
10131048

1049+
/**
1050+
* $params['body'] = (string) The script to execute
1051+
*
1052+
* @return callable|array
1053+
*/
1054+
public function scriptsPainlessExecute(array $params = [])
1055+
{
1056+
$body = $this->extractArgument($params, 'body');
1057+
/**
1058+
* @var callable $endpointBuilder
1059+
*/
1060+
$endpointBuilder = $this->endpoints;
1061+
/**
1062+
* @var \Elasticsearch\Endpoints\ScriptsPainlessExecute $endpoint
1063+
*/
1064+
$endpoint = $endpointBuilder('ScriptsPainlessExecute');
1065+
$endpoint->setBody($body);
1066+
$endpoint->setParams($params);
1067+
return $this->performRequest($endpoint);
1068+
}
1069+
10141070
/**
10151071
* $params['scroll_id'] = (string) The scroll ID for scrolled search
10161072
* ['scroll'] = (duration) Specify how long a consistent view of the index should be maintained for scrolled search

src/Elasticsearch/Connections/Connection.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Elasticsearch\Connections;
66

7+
use Elasticsearch\Client;
78
use Elasticsearch\Common\Exceptions\AlreadyExpiredException;
89
use Elasticsearch\Common\Exceptions\BadRequest400Exception;
910
use Elasticsearch\Common\Exceptions\Conflict409Exception;
@@ -126,6 +127,15 @@ public function __construct(
126127
unset($connectionParams['client']['headers']);
127128
}
128129

130+
// Add the User-Agent using the format: <client-repo-name>/<client-version> (metadata-values)
131+
$this->headers['User-Agent'] = [sprintf(
132+
"elasticsearch-php/%s (%s %s, PHP %s)",
133+
Client::VERSION,
134+
php_uname("s"),
135+
php_uname("r"),
136+
phpversion()
137+
)];
138+
129139
$host = $hostDetails['host'].':'.$hostDetails['port'];
130140
$path = null;
131141
if (isset($hostDetails['path']) === true) {
@@ -179,6 +189,12 @@ public function performRequest($method, $uri, $params = null, $body = null, $opt
179189
return $future;
180190
}
181191

192+
/** @return array */
193+
public function getHeaders()
194+
{
195+
return $this->headers;
196+
}
197+
182198
/** @return string */
183199
public function getTransportSchema()
184200
{

src/Elasticsearch/Endpoints/Cluster/AllocationExplain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ public function getParamWhitelist()
5959
*/
6060
public function getMethod()
6161
{
62-
return 'GET';
62+
return isset($this->body) ? 'POST' : 'GET';
6363
}
6464
}

src/Elasticsearch/Endpoints/Count.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public function getParamWhitelist()
8484
*/
8585
public function getMethod()
8686
{
87-
return 'GET';
87+
return isset($this->body) ? 'POST' : 'GET';
8888
}
8989
}

src/Elasticsearch/Endpoints/Explain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ public function getParamWhitelist()
9797
*/
9898
public function getMethod()
9999
{
100-
return 'GET';
100+
return isset($this->body) ? 'POST' : 'GET';
101101
}
102102
}

src/Elasticsearch/Endpoints/FieldCaps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public function getParamWhitelist()
6666
*/
6767
public function getMethod()
6868
{
69-
return 'GET';
69+
return isset($this->body) ? 'POST' : 'GET';
7070
}
7171
}

src/Elasticsearch/Endpoints/Indices/Analyze.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ public function getParamWhitelist()
7676
*/
7777
public function getMethod()
7878
{
79-
return 'GET';
79+
return isset($this->body) ? 'POST' : 'GET';
8080
}
8181
}

src/Elasticsearch/Endpoints/Indices/ClearCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ public function getParamWhitelist()
5959
*/
6060
public function getMethod()
6161
{
62-
return 'GET';
62+
return isset($this->body) ? 'POST' : 'GET';
6363
}
6464
}

src/Elasticsearch/Endpoints/Indices/Flush.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public function getParamWhitelist()
6363
*/
6464
public function getMethod()
6565
{
66-
return 'GET';
66+
return isset($this->body) ? 'POST' : 'GET';
6767
}
6868
}

src/Elasticsearch/Endpoints/Indices/ValidateQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ public function getParamWhitelist()
7474
*/
7575
public function getMethod()
7676
{
77-
return 'GET';
77+
return isset($this->body) ? 'POST' : 'GET';
7878
}
7979
}

0 commit comments

Comments
 (0)