init_js
init_js

Reputation: 4591

How to delete mutiple documents by ID in elasticsearch?

I am trying to delete a short list of documents in one swoop on Elasticsearch 2.4, and I can't seem to give it a query that results in >0 documents getting deleted.

id_list = ["AWeKNmt5qJi-jqXwc6qO", "AWeKT7ULqJi-jqXwc6qS"] #example

# The following does not delete any document (despite these ids being valid)
delres = es.delete_by_query("my_index", doc_type="my_doctype", body={
    "query": {
        "terms": {
            "_id": id_list
        }
    }
})

If I go one by one, then they get deleted just fine. Which seems to point to my query being the problem.

for the_id in id_list:
    es.delete("my_index", doc_type="my_doctype", id=the_id)

I've also tried the ids query instead of terms, but that also does not delete anything.

es.delete_by_query(..., body = {"query": {"ids" { "values": id_list }}})

What am I missing?

Upvotes: 0

Views: 774

Answers (1)

keithmo
keithmo

Reputation: 4943

delete_by_query was deprecated in ES 1.5.3, removed in ES 2.0, and reintroduced in ES 5.0. From https://www.elastic.co/guide/en/elasticsearch/reference/1.7/docs-delete-by-query.html:

Delete by Query will be removed in 2.0: it is problematic since it silently forces a refresh which can quickly cause OutOfMemoryError during concurrent indexing, and can also cause primary and replica to become inconsistent. Instead, use the scroll/scan API to find all matching ids and then issue a bulk request to delete them.

Upvotes: 1

Related Questions