Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you delete all indexes in elastic search using node.js?

The documentation recommends the following function to delete a specific index:

client.delete({
  index: 'myindex',
  type: 'mytype',
  id: '1'
}, function (error, response) {
  // ...
});

Which I have adapted to:

client.delete({
  index: '_all'
}, function (error, response) {
  // ...
});

But that gives me the following error:

Unable to build a path with those params. Supply at least index, type, id

I've been searching around for a couple of hours to no avail, anyone have any ideas?

like image 422
NYC Tech Engineer Avatar asked Aug 10 '15 18:08

NYC Tech Engineer


People also ask

How do I delete all indexes in Elasticsearch?

To delete all indices, use _all or * . To disallow the deletion of indices with _all or wildcard expressions, set the action. destructive_requires_name cluster setting to true .

Which of the following commands is used to delete an index from Elasticsearch?

How to Delete an Index? Once you have the index you wish to remove from Elasticsearch, use the DELETE request followed by the index name.

How do I remove indices in Opensearch?

If you no longer need an index, you can use the delete index API operation to delete it.


1 Answers

So, turns out I was using the wrong method. The below should take care of deleting all the indexes.

client.indices.delete({
    index: '_all'
}, function(err, res) {

    if (err) {
        console.error(err.message);
    } else {
        console.log('Indexes have been deleted!');
    }
});

You can introduce specific index names within that 'index' parameter, and you can also use '*' as an alternate to '_all'.

like image 64
NYC Tech Engineer Avatar answered Oct 18 '22 21:10

NYC Tech Engineer