title: ElasticSearch: How to remove from an index all documents that have a certain field with a specific value
body: <p>Im using the following request in order to delete all documents that have the field 'email' with a certain string:</p>
  <p>POST http://localhost:9200/&lt;index_name&gt;/_delete_by_query</p>
  <pre><code>{
    &quot;query&quot;: {
          &quot;match&quot;: {
              &quot;email&quot;: &quot;random@domain.com&quot;
          }
      }
  }
  </code></pre>
  <p>(source: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#docs-delete-by-query" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#docs-delete-by-query</a>)</p>
  <p>But every time I do the request above it deletes all documents (even the ones with different emails). I tested it and if the strings are very different it deletes correctly, in my particular case as the domain of all emails is the same it seems that it deletes all indiscriminately.</p>
  <p>Documents have the following format:</p>
  <pre><code>&quot;hits&quot;: [
              {
                  &quot;_index&quot;: &quot;users&quot;,
                  &quot;_type&quot;: &quot;_doc&quot;,
                  &quot;_id&quot;: &quot;AdkEdwadwEGn7QTAWm&quot;,
                  &quot;_score&quot;: 1.0,
                  &quot;_source&quot;: {
                      &quot;email&quot;: &quot;1984@domain.com&quot;,
                      &quot;token_type&quot;: &quot;Bearer&quot;,
                      &quot;expires_in&quot;: 2699,
                      &quot;access_token&quot;: &quot;dGSENKLSBPU&quot;
                  }
              },
              {
                  &quot;_index&quot;: &quot;users&quot;,
                  &quot;_type&quot;: &quot;_doc&quot;,
                  &quot;_id&quot;: &quot;A9kEeHadw0HEGn7QZwW2&quot;,
                  &quot;_score&quot;: 1.0,
                  &quot;_source&quot;: {
                      &quot;email&quot;: &quot;1244@domain.com&quot;,
                      &quot;token_type&quot;: &quot;Bearer&quot;,
                      &quot;expires_in&quot;: 2699,
                      &quot;access_token&quot;: &quot;dGSENKLSsdBPU&quot;
                  }
              },
  ....
              {
                  &quot;_index&quot;: &quot;users&quot;,
                  &quot;_type&quot;: &quot;_doc&quot;,
                  &quot;_id&quot;: &quot;AaoisAnskw0HEGn7QZwW2&quot;,
                  &quot;_score&quot;: 1.0,
                  &quot;_source&quot;: {
                      &quot;email&quot;: &quot;1984@domain.com&quot;,
                      &quot;token_type&quot;: &quot;Bearer&quot;,
                      &quot;expires_in&quot;: 2699,
                      &quot;access_token&quot;: &quot;dGSENKLSsdBPU&quot;
                  }
              }
          ]
  </code></pre>
  <p>My doubt is, how do i delete all documents with email = &quot;1984@domain.com&quot;?</p>
  <p>Thanks in advance!</p>