Skip to content

Commit 412f866

Browse files
fvilpoixruflin
authored andcommitted
add request params to client->deleteDocuments (#1419)
1 parent 93620a3 commit 412f866

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file based on the
1111

1212
### Added
1313

14+
* Added request parameters to `Client->deleteDocuments()`. [#1419](https://github.com/ruflin/Elastica/pull/1419)
15+
1416
### Improvements
1517

1618
### Deprecated

lib/Elastica/Client.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,13 @@ protected function _populateDocumentFieldsFromResponse(Response $response, Docum
481481
* Bulk deletes documents.
482482
*
483483
* @param array|\Elastica\Document[] $docs
484+
* @param array $requestParams
484485
*
485486
* @throws \Elastica\Exception\InvalidException
486487
*
487488
* @return \Elastica\Bulk\ResponseSet
488489
*/
489-
public function deleteDocuments(array $docs)
490+
public function deleteDocuments(array $docs, array $requestParams = [])
490491
{
491492
if (empty($docs)) {
492493
throw new InvalidException('Array has to consist of at least one element');
@@ -495,6 +496,10 @@ public function deleteDocuments(array $docs)
495496
$bulk = new Bulk($this);
496497
$bulk->addDocuments($docs, Action::OP_TYPE_DELETE);
497498

499+
foreach ($requestParams as $key => $value) {
500+
$bulk->setRequestParam($key, $value);
501+
}
502+
498503
return $bulk->send();
499504
}
500505

test/Elastica/ClientTest.php

+43
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,49 @@ public function testDeleteDocuments()
927927
$this->assertEquals(1, $type->count());
928928
}
929929

930+
/**
931+
* @group functional
932+
*/
933+
public function testDeleteDocumentsWithRequestParameters()
934+
{
935+
$index = $this->_createIndex();
936+
$type = $index->getType('test');
937+
$client = $index->getClient();
938+
939+
$docs = [
940+
new Document(1, ['field' => 'value1'], $type, $index),
941+
new Document(2, ['field' => 'value2'], $type, $index),
942+
new Document(3, ['field' => 'value3'], $type, $index),
943+
];
944+
945+
$response = $client->addDocuments($docs);
946+
947+
$this->assertInstanceOf(ResponseSet::class, $response);
948+
$this->assertEquals(3, count($response));
949+
$this->assertTrue($response->isOk());
950+
$this->assertFalse($response->hasError());
951+
$this->assertEquals('', $response->getError());
952+
953+
$index->refresh();
954+
955+
$this->assertEquals(3, $type->count());
956+
957+
$deleteDocs = [
958+
$docs[0],
959+
$docs[2],
960+
];
961+
962+
$response = $client->deleteDocuments($deleteDocs, ['refresh' => true]);
963+
964+
$this->assertInstanceOf(ResponseSet::class, $response);
965+
$this->assertEquals(2, count($response));
966+
$this->assertTrue($response->isOk());
967+
$this->assertFalse($response->hasError());
968+
$this->assertEquals('', $response->getError());
969+
970+
$this->assertEquals(1, $type->count());
971+
}
972+
930973
/**
931974
* @group functional
932975
*/

0 commit comments

Comments
 (0)