| endpoint | delete_by_query |
|---|---|
| lang | python |
| es_version | 9.3 |
| client | elasticsearch==9.3.0 |
Use client.delete_by_query() to delete all documents matching a
query. This is the bulk equivalent of delete.
response = client.delete_by_query(
index="products",
query={"term": {"category": "furniture"}},
)
print(f"Deleted {response['deleted']} documents")By default, version conflicts abort the operation. Set
conflicts="proceed" to skip conflicting documents and continue:
response = client.delete_by_query(
index="products",
query={"range": {"rating": {"lt": 4.0}}},
conflicts="proceed",
)
print(f"Deleted {response['deleted']}, conflicts: {response['version_conflicts']}")Use max_docs to cap the number of deletions, and scroll_size to
control how many documents are processed per batch:
response = client.delete_by_query(
index="products",
query={"match_all": {}},
max_docs=100,
scroll_size=50,
)