Elasticsearch delete_by_query wrong usage
<p>
I am using 2 similar ES methods to load and delete documents:</p>

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

<p>And:</p>

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

<p>First one works ok and returns expected records.<br>
Second one throws Exception:</p>

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

<p>What am I doing wrong?</p>

<p>If you're running ES 2.x, you need to make sure that you have installed the <a href="https://www.elastic.co/guide/en/elasticsearch/plugins/2.4/plugins-delete-by-query.html" rel="nofollow">delete-by-query plugin</a> first:</p>

<p>In your ES_HOME folder, run this:</p>

<pre><code>bin/plugin install delete-by-query
</code></pre>

<p>Then restart ES and your <code>es.delete_by_query(...)</code> call will work.</p>

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

python elasticsearch elasticsearch-py