Skip to content

Latest commit

 

History

History
47 lines (38 loc) · 1.07 KB

File metadata and controls

47 lines (38 loc) · 1.07 KB
endpoint delete_by_query
lang python
es_version 9.3
client elasticsearch==9.3.0

Elasticsearch 9.3 delete_by_query endpoint (Python example)

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")

Handling conflicts

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']}")

Limiting scope

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,
)