diff --git a/CHANGELOG.md b/CHANGELOG.md index 65875293d9..4b8df8893f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/Elastica/Index.php b/lib/Elastica/Index.php index 4d617ae093..2e632cbe16 100644 --- a/lib/Elastica/Index.php +++ b/lib/Elastica/Index.php @@ -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 { @@ -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); } /** diff --git a/test/Elastica/IndexTest.php b/test/Elastica/IndexTest.php index 7a5b6037df..ffc79c9d8e 100644 --- a/test/Elastica/IndexTest.php +++ b/test/Elastica/IndexTest.php @@ -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();