Elastica\Index::deleteDocuments PHP Method

deleteDocuments() public method

Uses _bulk to delete documents from the server.
public deleteDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet
    public function deleteDocuments(array $docs)
    {
        foreach ($docs as $doc) {
            $doc->setIndex($this->getName());
        }
        return $this->getClient()->deleteDocuments($docs);
    }

Usage Example

 /**
  * @param array $dataSet
  *
  * @throws \Spryker\Zed\Collector\Business\Exporter\Exception\InvalidDataSetException
  *
  * @return bool
  */
 public function delete(array $dataSet)
 {
     if ($this->hasIntegerKeys($dataSet)) {
         throw new InvalidDataSetException();
     }
     try {
         $documents = [];
         foreach ($dataSet as $key => $value) {
             $documents[] = $this->index->getType($this->type)->getDocument($key);
         }
         $response = $this->index->deleteDocuments($documents);
         $this->index->flush(true);
         return $response->isOk();
     } catch (\Exception $exception) {
         return true;
     }
 }