Elasticquent icon indicating copy to clipboard operation
Elasticquent copied to clipboard

About delete

Open marciomansur opened this issue 9 years ago • 3 comments

I'm using Elasticquent to work with mysql. When I update and insert data, the addAllToIndex and reindex methods works great. But when I want to delete something, the data that I deleted is still there.

How can I delete data in elasticquent?

marciomansur avatar Mar 15 '15 14:03 marciomansur

/** * Remove From Search Index * * @return array */ public function removeFromIndex() { return $this->getElasticSearchClient()->delete($this->getBasicEsParams()); }

/** * Delete From Index * * @return array */ public function deleteFromIndex() { $all = $this->all();

    $params = array();

    foreach ($all as $item) {

        $params['body'][] = array(
            'delete' => array(
                '_id' => $item->getKey(),
                '_type' => $item->getTypeName(),
                '_index' => $item->getIndexName()
            )
        );
    }

    return $this->getElasticSearchClient()->bulk($params);
}

kiwo12345 avatar Mar 17 '15 17:03 kiwo12345

How do I call it? I didn't find this on Elasticquent documentation. Do I need to instantiate the ElasticquentTrait?

marciomansur avatar Mar 19 '15 02:03 marciomansur

check this solution for reference https://github.com/elasticquent/Elasticquent/issues/36#issuecomment-184631352

nagibmahfuj avatar Feb 16 '16 11:02 nagibmahfuj