Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete document matching a query using official elasticsearch nodejs client?

I want to perform a delete-by-query, specifically delete all documents that have a field Kname that contains Gary. I am using the latest version of elasticsearch (2.3) I am using the official ES client:

elasticsearch-js

How can I perform such a deletion? Is it not supported? If not, appreciate any code/alternatives.

like image 365
Rolando Avatar asked May 12 '16 04:05

Rolando


1 Answers

Since you are on ES 2.x, delete-by-query is now a plugin, so you need to install it first and then also require the deleteByQuery extension library for the Javascript client.

Then you can perform

    client.deleteByQuery({
        index: 'test',
        type: 'something',
        body: {
           query: {
               match: { Kname: 'gary' }
           }
        }
    }, function (error, response) {
        console.log(response);
    });
like image 155
Val Avatar answered Nov 14 '22 21:11

Val