Elastica\Type::deleteById PHP Method

deleteById() public method

Deletes an entry by its unique identifier.
public deleteById ( integer | string $id, array $options = [] ) : Response
$id integer | string Document id
$options array
return Response Response object
    public function deleteById($id, array $options = [])
    {
        if (empty($id) || !trim($id)) {
            throw new \InvalidArgumentException();
        }
        $id = urlencode($id);
        $response = $this->request($id, Request::DELETE, [], $options);
        $responseData = $response->getData();
        if (isset($responseData['found']) && false == $responseData['found']) {
            throw new NotFoundException('Doc id ' . $id . ' not found and can not be deleted');
        }
        return $response;
    }

Usage Example

Example #1
1
 /**
  * remove the eav deleted products from elasticsearch index
  *
  * @param array $productIds
  */
 public function cleanElasticSearchIndex(array $productIds)
 {
     foreach ($productIds as $productId) {
         try {
             $this->_type->deleteById($productId);
         } catch (Exception $e) {
             //continue if $productId not found
             //TODO Logging
             continue;
         }
     }
 }
All Usage Examples Of Elastica\Type::deleteById