Skip to content

Commit

Permalink
Updated CHANGELOG + fixed CS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Jul 19, 2019
2 parents 3331fe5 + acbc76d commit da872d5
Show file tree
Hide file tree
Showing 24 changed files with 301 additions and 19 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Release 6.7.1

- Fix #846 choosing `GET` and `POST` in endpoints based on body [[acbc76d0]](https://github.com/elastic/elasticsearch-php/commit/acbc76d0)
- Fix #843 adding `wait_for_active_shards` and `pipeline` in `UpdateByQuery` [[acbc76d0]](https://github.com/elastic/elasticsearch-php/commit/acbc76d0)
- Fixed missing `ScriptsPainlessExecute` endpoint, since ES 6.3 [[acbc76d0]](https://github.com/elastic/elasticsearch-php/commit/acbc76d0)
- Fixed missing `RankEval` endpoint, since ES 6.2 [[acbc76d0]](https://github.com/elastic/elasticsearch-php/commit/acbc76d0)
- Added User-Agent header equal to `elasticsearch-php/6.7.1 (metadata-values)` [[acbc76d0]](https://github.com/elastic/elasticsearch-php/commit/acbc76d0)

## Release 6.7.0

- Removed requirement of `{type}` part in `indices.put_mapping`, see new API specification [here](https://github.com/elastic/elasticsearch/blob/v6.7.0/rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_mapping.json)
Expand Down Expand Up @@ -29,7 +37,7 @@
- [DOCS] Update `community.asciidoc`, added `ElasticSearchQueryDSL` project [#749](https://github.com/elastic/elasticsearch-php/pull/749)
- [DOCS] Proper return type array for get method for `IndicesNamespace` [#651](https://github.com/elastic/elasticsearch-php/pull/651)
- [DOCS] Fix full docs link [#862](https://github.com/elastic/elasticsearch-php/pull/862)
- [DOCS] Update breaking-changes.asciidoc, removal of ClientBuilder::defaultLogger() [879](https://github.com/elastic/elasticsearch-php/pull/879)
- [DOCS] Update breaking-changes.asciidoc, removal of ClientBuilder::defaultLogger() [#879](https://github.com/elastic/elasticsearch-php/pull/879)

### Testing

Expand Down
56 changes: 56 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*/
class Client
{
const VERSION = '6.7.1';

/**
* @var Transport
*/
Expand Down Expand Up @@ -155,6 +157,39 @@ public function ping($params = [])
return true;
}

/**
* $params['body'] = (string) The ranking evaluation search definition, including
* search requests, document ratings and ranking metric definition (Required)
* ['index'] = (list) A comma-separated list of index names to search; use `_all` or
* empty string to perform the operation on all indices
* ['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.
*
* @return callable|array
*/
public function rankEval(array $params)
{
$body = $this->extractArgument($params, 'body');
$index = $this->extractArgument($params, 'index');
/**
* @var callable $endpointBuilder
*/
$endpointBuilder = $this->endpoints;
/**
* @var \Elasticsearch\Endpoints\RankEval $endpoint
*/
$endpoint = $endpointBuilder('RankEval');
$endpoint->setBody($body)
->setIndex($index);
$endpoint->setParams($params);

return $this->performRequest($endpoint);
}

/**
* $params['id'] = (string) The document ID (Required)
* ['index'] = (string) The name of the index (Required)
Expand Down Expand Up @@ -1021,6 +1056,27 @@ public function scroll($params = array())
return $this->performRequest($endpoint);
}

/**
* $params['body'] = (string) The script to execute
*
* @return callable|array
*/
public function scriptsPainlessExecute(array $params = [])
{
$body = $this->extractArgument($params, 'body');
/**
* @var callable $endpointBuilder
*/
$endpointBuilder = $this->endpoints;
/**
* @var \Elasticsearch\Endpoints\ScriptsPainlessExecute $endpoint
*/
$endpoint = $endpointBuilder('ScriptsPainlessExecute');
$endpoint->setBody($body);
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}

/**
* $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
16 changes: 16 additions & 0 deletions src/Elasticsearch/Connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Elasticsearch\Connections;

use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\AlreadyExpiredException;
use Elasticsearch\Common\Exceptions\BadRequest400Exception;
use Elasticsearch\Common\Exceptions\Conflict409Exception;
Expand Down Expand Up @@ -126,6 +127,15 @@ public function __construct(
unset($connectionParams['client']['headers']);
}

// Add the User-Agent using the format: <client-repo-name>/<client-version> (metadata-values)
$this->headers['User-Agent'] = [sprintf(
"elasticsearch-php/%s (%s %s, PHP %s)",
Client::VERSION,
php_uname("s"),
php_uname("r"),
phpversion()
)];

$host = $hostDetails['host'].':'.$hostDetails['port'];
$path = null;
if (isset($hostDetails['path']) === true) {
Expand Down Expand Up @@ -179,6 +189,12 @@ public function performRequest($method, $uri, $params = null, $body = null, $opt
return $future;
}

/** @return array */
public function getHeaders()
{
return $this->headers;
}

/** @return string */
public function getTransportSchema()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Cluster/AllocationExplain.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Explain.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/FieldCaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Indices/Analyze.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Indices/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Indices/Flush.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Indices/ValidateQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Ingest/Simulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/MTermVectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'POST';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Msearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ public function getBody()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/MsearchTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ public function getBody()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
61 changes: 61 additions & 0 deletions src/Elasticsearch/Endpoints/RankEval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types = 1);

namespace Elasticsearch\Endpoints;

/**
* Class RankEval
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints
* @author Enrico Zimuel <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elastic.co
*/
class RankEval extends AbstractEndpoint
{
/**
* @return array
*/
public function getParamWhitelist()
{
return [
'ignore_unavailable',
'allow_no_indices',
'expand_wildcards'
];
}

/**
* @return string
*/
public function getURI()
{
$index = $this->index ?? null;
if (isset($index)) {
return "/$index/_rank_eval";
}
return '/_rank_eval';
}

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

/**
* @param array $body
* @return $this
*/
public function setBody($body)
{
if (isset($body) !== true) {
return $this;
}
$this->body = $body;
return $this;
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/RenderSearchTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public function getBody()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
58 changes: 58 additions & 0 deletions src/Elasticsearch/Endpoints/ScriptsPainlessExecute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Endpoints;

use Elasticsearch\Common\Exceptions\RuntimeException;

/**
* Class Reindex
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints
* @author Enrico Zimuel <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elastic.co
*/
class ScriptsPainlessExecute extends AbstractEndpoint
{
/**
* @return array
*/
public function getParamWhitelist()
{
return [];
}

/**
* @return string
*/
public function getURI()
{
return "/_scripts/painless/_execute";
}

/**
* @return string
*/
public function getMethod()
{
return isset($this->body) ? 'POST' : 'GET';
}

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

$this->body = $body;

return $this;
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Scroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/SearchTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'GET';
return isset($this->body) ? 'POST' : 'GET';
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/TermVectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public function getParamWhitelist()
*/
public function getMethod()
{
return 'POST';
return isset($this->body) ? 'POST' : 'GET';
}
}
Loading

0 comments on commit da872d5

Please sign in to comment.