diff --git a/CHANGELOG.md b/CHANGELOG.md index 0185c420a..d9fe6446a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated ### Removed ### Fixed +* `Elastica\Index::refresh()` now refreshes only the targeted index instead of the entire cluster (previously it issued `POST /_refresh`, now it issues `POST /{index}/_refresh`) [#2313](https://github.com/ruflin/Elastica/issues/2313) ### Security diff --git a/src/Index.php b/src/Index.php index 6d042ed52..f8dd7fe2b 100644 --- a/src/Index.php +++ b/src/Index.php @@ -470,7 +470,7 @@ public function forcemerge($args = []): Response public function refresh(): Response { return $this->_client->toElasticaResponse( - $this->_client->indices()->refresh() + $this->_client->indices()->refresh(['index' => $this->getName()]) ); } diff --git a/tests/IndexTest.php b/tests/IndexTest.php index 3021fc44f..d6d4fe158 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -18,6 +18,7 @@ use Elastica\Status; use Elastica\Test\Base as BaseTest; use PHPUnit\Framework\Attributes\Group; +use Psr\Http\Message\RequestInterface; /** * @internal @@ -1028,4 +1029,23 @@ public function testAddDocumentWithStaleIfSeqNoFailsWithVersionConflict(): void $this->expectException(ClientResponseException::class); $index->addDocument($second); } + + #[Group('functional')] + public function testRefreshTargetsIndexAndNotCluster(): void + { + $index = $this->_createIndex(); + $client = $index->getClient(); + + $response = $index->refresh(); + + $this->assertTrue($response->isOk()); + + $lastRequest = $client->getLastRequest(); + $this->assertInstanceOf(RequestInterface::class, $lastRequest); + $this->assertSame( + \sprintf('/%s/_refresh', $index->getName()), + $lastRequest->getUri()->getPath(), + 'Index::refresh() must target the specific index, not the whole cluster' + ); + } }