A delete request allows us to delete document(s) from an index based on an id or query.
For example, to delete a single document by id in an index called places
:
client.execute {
deleteById("places", "3")
}
We can take this a step further by deleting using a query rather than directly by id. In this example we're deleting all bands where their type is pop.
client.execute {
deleteByQuery("bands", termQuery("type", "pop"))
}
Delete is bulk compatible so we can issue multiple requests at once:
client.bulk {
deleteById("places", "4")
deleteById("places", "5")
deleteById("places", "6")
}
To delete an entire index you can use deleteIndex
:
client.execute {
deleteIndex("places")
}
Or do delete all indices (careful!):
client.execute {
deleteIndex("_all")
}