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 'Elastica\Client::closePointInTime()' for closing a PiT #1995

Merged
merged 1 commit into from
Oct 20, 2021
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 @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
29 changes: 29 additions & 0 deletions tests/PointInTimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Elastica\Test;

use Elastica\Test\Base as BaseTest;

/**
* @internal
*/
class PointInTimeTest extends BaseTest
{
/**
* @group functional
*/
public function testOpenClosePointInTime(): void
{
$index = $this->_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());
}
}