Skip to content

Commit

Permalink
Added ability get defaults index settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihails Krasilnikovs committed Aug 16, 2022
1 parent 535fb09 commit e4ee8b1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Index/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,24 @@ public function __construct(BaseIndex $index)
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
*/
public function get(string $setting = '')
public function get(string $setting = '', bool $includeDefaults = false)
{
$requestData = $this->request()->getData();
$queryParameters = [
'include_defaults' => $includeDefaults,
];

$requestData = $this->request([], Request::GET, $queryParameters)->getData();
$data = \reset($requestData);

if (empty($data['settings']) || empty($data['settings']['index'])) {
// should not append, the request should throw a ResponseException
throw new NotFoundException('Index '.$this->getIndex()->getName().' not found');
}

$settings = $data['settings']['index'];
$defaults = $data['defaults']['index'] ?? [];

$settings = array_merge($defaults, $settings);

if (!$setting) {
// return all array
Expand Down Expand Up @@ -329,14 +337,14 @@ public function getIndex(): BaseIndex
*
* @return Response Response object
*/
public function request(array $data = [], string $method = Request::GET): Response
public function request(array $data = [], string $method = Request::GET, array $queryParameters = []): Response
{
$path = '_settings';

if ($data) {
$data = ['index' => $data];
}

return $this->getIndex()->request($path, $method, $data);
return $this->getIndex()->request($path, $method, $data, $queryParameters);
}
}

0 comments on commit e4ee8b1

Please sign in to comment.