0

I am using 2 similar ES methods to load and delete documents:

result = es.search(index='users_favourite_documents',
                   doc_type='favourite_document',
                   body={"query": {"match": {'user': user}}})

And:

result = es.delete_by_query(index='users_favourite_documents',
                            doc_type='favourite_document',
                            body={"query": {"match": {'user': user}}})

First one works ok and returns expected records.
Second one throws Exception:

"TransportError(404,'{
\"found\":false,
\"_index\":\"users_favourite_documents\",
\"_type\":\"favourite_document\",
\"_id\":\"_query\", \"_version\":1,
\"_shards\":{\"total\":2,\"successful\":2, \"failed\":0}}')"

What am I doing wrong?

4
  • What version of ES are you using? Commented Sep 5, 2016 at 11:11
  • 1
    Version of ES == 2.3 Commented Sep 5, 2016 at 12:31
  • Unfortunately it's not mine ES server. I managed to solve problem by using search as first step to get _id and normal delete() (which uses previously acquired _id) as the second step. Commented Sep 5, 2016 at 14:20
  • Ok, gotcha. If you manage to get a hand on the server, the answer will still be valid, though. Commented Sep 5, 2016 at 14:21

2 Answers 2

5

I'v used version 6.2.0 of the Elastic Stack and the use of the API works for deleting like this:

es.delete_by_query(index="index_name", doc_type='doc_type', body={"query":{"match": {"message": "message_value"}}})

if your value is INT remove the "" in message_value.

Sign up to request clarification or add additional context in comments.

Comments

1

If you're running recent versions of ES (5/6/7/8), the _delete_by_query endpoint is supported natively. No need to install anything.

If you're running ES 2.x, you need to make sure that you have installed the delete-by-query plugin first:

In your ES_HOME folder, run this:

bin/plugin install delete-by-query

Then restart ES and your es.delete_by_query(...) call will work.

If you're running ES 1.x, then delete-by-query is part of the core and that should work out of the box.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.