Skip to content

Commit

Permalink
Do not throw NotFoundException when deleting documents by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Dec 11, 2019
1 parent 8729b7d commit 863e521
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file based on the

### Backward Compatibility Breaks

* The method `Index::deleteById()` does not throw an `NotFoundException` when deleting a non-existing document [#1732](https://github.com/ruflin/Elastica/pull/1732)
* The class `\Elastica\QueryBuilder\Version\Version240` has been moved to `\Elastica\QueryBuilder\Version\Version700` [#1693](https://github.com/ruflin/Elastica/pull/1693)
* Dropped support for PHP 7.1 [#1703](https://github.com/ruflin/Elastica/pull/1703)

Expand Down
16 changes: 1 addition & 15 deletions lib/Elastica/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ public function getDocument($id, array $options = []): Document
* Deletes a document by its unique identifier.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
*
* @param string $id Document id
*
* @throws NotFoundException
*
* @return Response Response object
*/
public function deleteById(string $id, array $options = []): Response
{
Expand All @@ -306,15 +300,7 @@ public function deleteById(string $id, array $options = []): Response
$endpoint->setID(\trim($id));
$endpoint->setParams($options);

$response = $this->requestEndpoint($endpoint);

$responseData = $response->getData();

if (isset($responseData['result']) && 'not_found' === $responseData['result']) {
throw new NotFoundException('Doc id "'.$id.'" not found and can not be deleted');
}

return $response;
return $this->requestEndpoint($endpoint);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/Elastica/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ public function testForcemerge()
$this->assertEquals(2, $stats['_all']['primaries']['docs']['count']);
$this->assertEquals(0, $stats['_all']['primaries']['docs']['deleted']);

$index->deleteById(1);
$index->deleteById('1');
$index->refresh();

$stats = $index->getStats()->getData();
Expand Down

0 comments on commit 863e521

Please sign in to comment.