# Delete By Query (Dry Run)

**URL:** <https://discuss.elastic.co/t/delete-by-query-dry-run/71308>\
**Category:** Elasticsearch\
**Created:** [January 12, 2017, 3:47am UTC](https://discuss.elastic.co/t/delete-by-query-dry-run/71308 "2017-01-12T03:47:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)\
**Post date:** [January 12, 2017, 3:47am UTC](https://discuss.elastic.co/t/delete-by-query-dry-run/71308/1 "2017-01-12T03:47:47Z")

</div>

I was looking to remove some bad fields from my documents and like this functionality but I don't see a dry run, test type option that would report back number of documents that would have been affected  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html)

Now obviously, I could make a copy of the index, and run it against that , but I was hoping that there was a "TEST" option that run's the DELETE but does not apply the actual changes.

I am working off this article as an example

> <https://stackoverflow.com/questions/29002215/remove-a-field-from-a-elasticsearch-document>

```auto
http://localhost:9200/type/_update_by_query?wait_for_completion=false&conflict=proceed
POST body:
{
  "script": ctx._source.remove("XXXXXXXXXXX"),
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "XXXXXXXXXXXXX"
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [January 12, 2017, 9:23am UTC](https://discuss.elastic.co/t/delete-by-query-dry-run/71308/2 "2017-01-12T09:23:48Z")

</div>

If you switch the endpoint from \_update\_by\_query to \_search and remove the  
top level script element you can see the docs it will try to hit.

Another option is to run reindex into a new index with the same query and  
look at the results. You can use the size parameter to stop after a certain  
number of changes for faster testing.

---

<div class="post-metadata">

**Author:** ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)\
**Post date:** [January 12, 2017, 2:58pm UTC](https://discuss.elastic.co/t/delete-by-query-dry-run/71308/3 "2017-01-12T14:58:00Z")

</div>

yah I thought about the \_search suggestion, one of my earlier tests was falling on a Max field value.

No worries, thought that making a copy was the only real way to test. Though my indexes are pretty large.

I think I will just work carefully on live data and in major issues restore one of my snapshots from S3. Just was hopping to avoid that .

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 9, 2017, 2:58pm UTC](https://discuss.elastic.co/t/delete-by-query-dry-run/71308/4 "2017-02-09T14:58:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
