Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About delete #22

Open
marciomansur opened this issue Mar 15, 2015 · 3 comments
Open

About delete #22

marciomansur opened this issue Mar 15, 2015 · 3 comments

Comments

@marciomansur
Copy link

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
Copy link

/**
* 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
Copy link
Author

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

@nagibmahfuj
Copy link

check this solution for reference elasticquent/Elasticquent#36 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants