From a32dbba0c7c448aa7d7502dededfe30040d878ed Mon Sep 17 00:00:00 2001 From: thePanz <226021+thePanz@users.noreply.github.com> Date: Mon, 18 Oct 2021 17:32:34 +0200 Subject: [PATCH] Add 'Elastica\Client::closePointInTime()' for closing a PiT --- CHANGELOG.md | 1 + src/Client.php | 14 ++++++++++++++ tests/PointInTimeTest.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/PointInTimeTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ade975f4a..c3c9cd2877 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added exposure of Point-In-Time ID for search responses in `Elastica\ResultSet::getPointInTimeId()` [#1991](https://github.com/ruflin/Elastica/pull/1991) * Added `Elastica\Index::openPointInTime()` for opening a PiT on the index [#1994](https://github.com/ruflin/Elastica/pull/1994) * Added possibility to specify PointInTime on `Elastica\Query::setPointInTime()` [#1992](https://github.com/ruflin/Elastica/pull/1992) +* Added `Elastica\Client::closePointInTime()` for closing a PiT [#1995](https://github.com/ruflin/Elastica/pull/1995) ### Changed * Updated `php-cs-fixer` to `2.18.6` [#1955](https://github.com/ruflin/Elastica/pull/1955) * Updated `php-cs-fixer` to `3.0.0` [#1959](https://github.com/ruflin/Elastica/pull/1959) diff --git a/src/Client.php b/src/Client.php index d36d115ace..456708de0a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -8,6 +8,7 @@ use Elastica\Exception\InvalidException; use Elastica\Script\AbstractScript; use Elasticsearch\Endpoints\AbstractEndpoint; +use Elasticsearch\Endpoints\ClosePointInTime; use Elasticsearch\Endpoints\Indices\ForceMerge; use Elasticsearch\Endpoints\Indices\Refresh; use Elasticsearch\Endpoints\Update; @@ -563,6 +564,19 @@ public function forcemergeAll($args = []): Response return $this->requestEndpoint($endpoint); } + /** + * Closes the given PointInTime. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html#close-point-in-time-api + */ + public function closePointInTime(string $pointInTimeId): Response + { + $endpoint = new ClosePointInTime(); + $endpoint->setBody(['id' => $pointInTimeId]); + + return $this->requestEndpoint($endpoint); + } + /** * Refreshes all search indices. * diff --git a/tests/PointInTimeTest.php b/tests/PointInTimeTest.php new file mode 100644 index 0000000000..3320ea3035 --- /dev/null +++ b/tests/PointInTimeTest.php @@ -0,0 +1,29 @@ +_createIndex(); + $pitOpenResponse = $index->openPointInTime('10s'); + $this->assertTrue($pitOpenResponse->isOk()); + + $pitId = $pitOpenResponse->getData()['id']; + + $client = $index->getClient(); + $pitCloseResponse = $client->closePointInTime($pitId); + $this->assertTrue($pitCloseResponse->isOk()); + + $this->assertArrayHasKey('num_freed', $pitCloseResponse->getData()); + } +}