Answer the question
In order to leave comments, you need to log in
How to delete documents matching a condition in Elasticsearch?
I used to use elasticutils in my Python script.
Now I am rewriting it to use the elasticsearch-dsl module.
Here is the old code:
from elasticutils import get_es
es = get_es(urls=config.ELASTIC_SEARCH_HOSTS, timeout=timeout)
es.delete_by_query(
'posts',
'post',
{'query': {'term': {'user_id': user.id}}})
Answer the question
In order to leave comments, you need to log in
Try it through a regular client (didn't check the code, pulled it from the source, but it should work)
from elasticsearch import Elasticsearch, helpers
es = Elasticsearch()
def mybulk_delete(q, index, doc_type):
res = helpers.scan(es,
query={"query": q},
index=index, doc_type= doc_type)
for r in res:
yield {"delete" : { "_index" : r["_index"], "_type" : r["_type"], "_id" : r["_id"] } }
q = {"query":{"term":{"user":"kimchy"}}}
k = (i for i in mybulk_delete(q,"myindex", "mytype"))
helpers.bulk(es, k, refresh = True)
For example, like this:
POST finrep/securities/_delete_by_query
{
"query": {
"match": {
"company_name": "ТрансКонтейнер"
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question