adamfairholm / Elasticquent

Map Larvel Eloquent models to Elasticsearch types
MIT License
201 stars 38 forks source link

About delete #22

Open marciomansur opened 9 years ago

marciomansur commented 9 years ago

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?

kiwo12345 commented 9 years ago

/* * 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);
}
marciomansur commented 9 years ago

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

nagibmahfuj commented 8 years ago

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