Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add refresh search analyzers api endpoint #154

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added class docs generator ([#96](https://github.com/opensearch-project/opensearch-php/pull/96))
- Added support for Amazon OpenSearch Serverless SigV4 signing ([#119](https://github.com/opensearch-project/opensearch-php/pull/119))
- Added `includePortInHostHeader` option to `ClientBuilder::fromConfig` ([#118](https://github.com/opensearch-project/opensearch-php/pull/118))
- Added the `RefreshSearchAnalyzers` endpoint ([[#152](https://github.com/opensearch-project/opensearch-php/issues/152))

### Changed

Expand Down
48 changes: 48 additions & 0 deletions src/OpenSearch/Endpoints/Indices/RefreshSearchAnalyzers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/**
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Elasticsearch PHP client
*
* @link https://github.com/elastic/elasticsearch-php/
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1
*
* Licensed to Elasticsearch B.V under one or more agreements.
* Elasticsearch B.V licenses this file to you under the Apache 2.0 License or
* the GNU Lesser General Public License, Version 2.1, at your option.
* See the LICENSE file in the project root for more information.
*/

namespace OpenSearch\Endpoints\Indices;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class RefreshSearchAnalyzers extends AbstractEndpoint
lukas-jansen marked this conversation as resolved.
Show resolved Hide resolved
{
public function getURI(): string
{
$index = $this->index ?? null;

if (isset($index)) {
return "/_plugins/_refresh_search_analyzers/$index";
}
throw new RuntimeException('Missing index parameter for the endpoint indices.refresh_search_analyzers');
}

public function getParamWhitelist(): array
{
return [];
}

public function getMethod(): string
{
return 'POST';
}
}
17 changes: 17 additions & 0 deletions src/OpenSearch/Namespaces/IndicesNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,23 @@ public function getDataStream(array $params = [])

return $this->performRequest($endpoint);
}
/**
* $params['index'] = (list) A comma-separated list of index names to refresh analyzers for
*
* @param array $params Associative array of parameters
* @return array
*/
public function refreshSearchAnalyzers(array $params = [])
{
$index = $this->extractArgument($params, 'index');

$endpointBuilder = $this->endpoints;
$endpoint = $endpointBuilder('Indices\RefreshSearchAnalyzers');
$endpoint->setParams($params);
$endpoint->setIndex($index);

return $this->performRequest($endpoint);
}
/**
* $params['index'] = (list) A comma-separated list of index names to reload analyzers for
* $params['ignore_unavailable'] = (boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)
Expand Down
109 changes: 109 additions & 0 deletions tests/Endpoints/RefreshSearchAnalyzersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

/**
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Elasticsearch PHP client
*
* @link https://github.com/elastic/elasticsearch-php/
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1
*
* Licensed to Elasticsearch B.V under one or more agreements.
* Elasticsearch B.V licenses this file to you under the Apache 2.0 License or
* the GNU Lesser General Public License, Version 2.1, at your option.
* See the LICENSE file in the project root for more information.
*/

namespace OpenSearch\Tests\Endpoints;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\Indices\RefreshSearchAnalyzers;

class RefreshSearchAnalyzersTest extends \PHPUnit\Framework\TestCase
{
/** @var RefreshSearchAnalyzers */
private $instance;

/**
* @inheritDoc
*/
protected function setUp(): void
{
// Instance
$this->instance = new RefreshSearchAnalyzers();
}

public function testGetURIWhenIndexAndIdAreDefined(): void
{
// Arrange
$expected = '/_plugins/_refresh_search_analyzers/index';

$this->instance->setIndex('index');
$this->instance->setId(10);

// Act
$result = $this->instance->getURI();

// Assert
$this->assertEquals($expected, $result);
}

public function testGetURIWhenIndexIsDefinedAndIdIsNotDefined(): void
{
// Arrange
$expected = '/_plugins/_refresh_search_analyzers/index';

$this->instance->setIndex('index');

// Act
$result = $this->instance->getURI();

// Assert
$this->assertEquals($expected, $result);
}

public function testGetURIWhenIndexIsNotDefined(): void
{
// Arrange
$expected = RuntimeException::class;
$expectedMessage = 'Missing index parameter for the endpoint indices.refresh_search_analyzers';

// Assert
$this->expectException($expected);
$this->expectExceptionMessage($expectedMessage);

// Act
$this->instance->getURI();
}

public function testGetMethodWhenIdIsDefined(): void
{
// Arrange
$expected = 'POST';

$this->instance->setId(10);

// Act
$result = $this->instance->getMethod();

// Assert
$this->assertEquals($expected, $result);
}

public function testGetMethodWhenIdIsNotDefined(): void
{
// Arrange
$expected = 'POST';

// Act
$result = $this->instance->getMethod();

// Assert
$this->assertEquals($expected, $result);
}
}