Chinovski
Chinovski

Reputation: 517

How to delete multiple documents in elasticsearch?

I want to delete many documents from elasticsearch that don't exist anymore on my database.

I know that to delete multiple documents (with ids 1,2,3 for example) we use :

curl -XDELETE localhost:9200/index/doc/ids=1,2,3

But I want to keep only those ids and delete the rest, it something like the following instruction in SQL.

DELETE FROM table1 WHERE id_column NOT IN (1,2,3);

Is there an equivalent of NOT IN in this case for elasticsearch?

Upvotes: 5

Views: 13112

Answers (1)

tomas
tomas

Reputation: 329

It may be little dangerous but you can use delete by query. delete by query api

The query will be something like this:

query : {bool : { must_not : {ids : values : [1,2,3,... ]}}}

Upvotes: 7

Related Questions