public deleteIds ( array $ids, string | |
||
$ids | array | Document ids |
$index | string | |
Index name |
$type | string | |
Type of documents |
$routing | string | boolean | Optional routing key for all ids |
Résultat | Response object |
public function deleteIds(array $ids, $index, $type, $routing = false)
{
if (empty($ids)) {
throw new InvalidException('Array has to consist of at least one id');
}
$bulk = new Bulk($this);
$bulk->setIndex($index);
$bulk->setType($type);
foreach ($ids as $id) {
$action = new Action(Action::OP_TYPE_DELETE);
$action->setId($id);
if (!empty($routing)) {
$action->setRouting($routing);
}
$bulk->addAction($action);
}
return $bulk->send();
}
/** * Perform a scan and scroll through the results, bulk deleting by result ids * * @param ClassMetadata $class * @param object $scanQuery * @param string $index */ private function deleteByScanScroll(ClassMetadata $class, $scanQuery, $index) { $type = $this->getIndex($index)->getType($class->type); $query = Query::create($scanQuery); $results = $this->scan($query, array($class)); foreach ($results as $collection) { $resultIds = array(); foreach ($collection->getResults() as $result) { $resultIds[] = $result->getId(); } $this->client->deleteIds($resultIds, $index, $type); } }