Skip to content

Commit 8b6cdbc

Browse files
authored
Add refresh search analyzers api endpoint (#154)
* Add refresh search analyzers api endpoint Signed-off-by: Lukas Jansen <[email protected]> Signed-off-by: GitHub <[email protected]> * Add unit test for RefreshSearchAnalyzers endpoint Signed-off-by: Lukas Jansen <[email protected]> Signed-off-by: GitHub <[email protected]> * Add changelog + fix phpstan Signed-off-by: Lukas Jansen <[email protected]> --------- Signed-off-by: Lukas Jansen <[email protected]> Signed-off-by: GitHub <[email protected]> Signed-off-by: Lukas Jansen <[email protected]>
1 parent aeb0163 commit 8b6cdbc

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88
- Added class docs generator ([#96](https://github.com/opensearch-project/opensearch-php/pull/96))
99
- Added support for Amazon OpenSearch Serverless SigV4 signing ([#119](https://github.com/opensearch-project/opensearch-php/pull/119))
1010
- Added `includePortInHostHeader` option to `ClientBuilder::fromConfig` ([#118](https://github.com/opensearch-project/opensearch-php/pull/118))
11+
- Added the `RefreshSearchAnalyzers` endpoint ([[#152](https://github.com/opensearch-project/opensearch-php/issues/152))
1112

1213
### Changed
1314

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright OpenSearch Contributors
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Elasticsearch PHP client
10+
*
11+
* @link https://github.com/elastic/elasticsearch-php/
12+
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
13+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
14+
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1
15+
*
16+
* Licensed to Elasticsearch B.V under one or more agreements.
17+
* Elasticsearch B.V licenses this file to you under the Apache 2.0 License or
18+
* the GNU Lesser General Public License, Version 2.1, at your option.
19+
* See the LICENSE file in the project root for more information.
20+
*/
21+
22+
namespace OpenSearch\Endpoints\Indices;
23+
24+
use OpenSearch\Common\Exceptions\RuntimeException;
25+
use OpenSearch\Endpoints\AbstractEndpoint;
26+
27+
class RefreshSearchAnalyzers extends AbstractEndpoint
28+
{
29+
public function getURI(): string
30+
{
31+
$index = $this->index ?? null;
32+
33+
if (isset($index)) {
34+
return "/_plugins/_refresh_search_analyzers/$index";
35+
}
36+
throw new RuntimeException('Missing index parameter for the endpoint indices.refresh_search_analyzers');
37+
}
38+
39+
public function getParamWhitelist(): array
40+
{
41+
return [];
42+
}
43+
44+
public function getMethod(): string
45+
{
46+
return 'POST';
47+
}
48+
}

src/OpenSearch/Namespaces/IndicesNamespace.php

+17
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,23 @@ public function getDataStream(array $params = [])
11731173

11741174
return $this->performRequest($endpoint);
11751175
}
1176+
/**
1177+
* $params['index'] = (list) A comma-separated list of index names to refresh analyzers for
1178+
*
1179+
* @param array $params Associative array of parameters
1180+
* @return array
1181+
*/
1182+
public function refreshSearchAnalyzers(array $params = [])
1183+
{
1184+
$index = $this->extractArgument($params, 'index');
1185+
1186+
$endpointBuilder = $this->endpoints;
1187+
$endpoint = $endpointBuilder('Indices\RefreshSearchAnalyzers');
1188+
$endpoint->setParams($params);
1189+
$endpoint->setIndex($index);
1190+
1191+
return $this->performRequest($endpoint);
1192+
}
11761193
/**
11771194
* $params['index'] = (list) A comma-separated list of index names to reload analyzers for
11781195
* $params['ignore_unavailable'] = (boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright OpenSearch Contributors
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Elasticsearch PHP client
10+
*
11+
* @link https://github.com/elastic/elasticsearch-php/
12+
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
13+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
14+
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1
15+
*
16+
* Licensed to Elasticsearch B.V under one or more agreements.
17+
* Elasticsearch B.V licenses this file to you under the Apache 2.0 License or
18+
* the GNU Lesser General Public License, Version 2.1, at your option.
19+
* See the LICENSE file in the project root for more information.
20+
*/
21+
22+
namespace OpenSearch\Tests\Endpoints;
23+
24+
use OpenSearch\Common\Exceptions\RuntimeException;
25+
use OpenSearch\Endpoints\Indices\RefreshSearchAnalyzers;
26+
27+
class RefreshSearchAnalyzersTest extends \PHPUnit\Framework\TestCase
28+
{
29+
/** @var RefreshSearchAnalyzers */
30+
private $instance;
31+
32+
/**
33+
* @inheritDoc
34+
*/
35+
protected function setUp(): void
36+
{
37+
// Instance
38+
$this->instance = new RefreshSearchAnalyzers();
39+
}
40+
41+
public function testGetURIWhenIndexAndIdAreDefined(): void
42+
{
43+
// Arrange
44+
$expected = '/_plugins/_refresh_search_analyzers/index';
45+
46+
$this->instance->setIndex('index');
47+
$this->instance->setId(10);
48+
49+
// Act
50+
$result = $this->instance->getURI();
51+
52+
// Assert
53+
$this->assertEquals($expected, $result);
54+
}
55+
56+
public function testGetURIWhenIndexIsDefinedAndIdIsNotDefined(): void
57+
{
58+
// Arrange
59+
$expected = '/_plugins/_refresh_search_analyzers/index';
60+
61+
$this->instance->setIndex('index');
62+
63+
// Act
64+
$result = $this->instance->getURI();
65+
66+
// Assert
67+
$this->assertEquals($expected, $result);
68+
}
69+
70+
public function testGetURIWhenIndexIsNotDefined(): void
71+
{
72+
// Arrange
73+
$expected = RuntimeException::class;
74+
$expectedMessage = 'Missing index parameter for the endpoint indices.refresh_search_analyzers';
75+
76+
// Assert
77+
$this->expectException($expected);
78+
$this->expectExceptionMessage($expectedMessage);
79+
80+
// Act
81+
$this->instance->getURI();
82+
}
83+
84+
public function testGetMethodWhenIdIsDefined(): void
85+
{
86+
// Arrange
87+
$expected = 'POST';
88+
89+
$this->instance->setId(10);
90+
91+
// Act
92+
$result = $this->instance->getMethod();
93+
94+
// Assert
95+
$this->assertEquals($expected, $result);
96+
}
97+
98+
public function testGetMethodWhenIdIsNotDefined(): void
99+
{
100+
// Arrange
101+
$expected = 'POST';
102+
103+
// Act
104+
$result = $this->instance->getMethod();
105+
106+
// Assert
107+
$this->assertEquals($expected, $result);
108+
}
109+
}

0 commit comments

Comments
 (0)