# Get count of deleted records by input query

**URL:** https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123
**Category:** Elasticsearch
**Created:** [May 26, 2013, 4:30am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123 "2013-05-26T04:30:41Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Ankit\_Jain](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Ankit\_Jain](https://discuss.elastic.co/u/Ankit_Jain)
#### Post date: [May 26, 2013, 4:30am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/1 "2013-05-26T04:30:41Z")

</div>

Hi All,

I executing query to delete records from ES, below is the code for the same.

DeleteByQueryRequestBuilder dbqb = client  
.prepareDeleteByQuery("index").setQuery(qb);

DeleteByQueryResponse deleteByQueryResponse = dbqb.execute()  
.actionGet();

The query is working fine, but not returning the count of deleted records.

Please suggest some way through which we can find the number of deleted  
records using the same query we used for deletion.

Thanks,  
Ankit Jain

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Saurabh\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabh_2/32/2320_2.png) [@Saurabh\_2](https://discuss.elastic.co/u/Saurabh_2)
#### Post date: [May 27, 2013, 11:26am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/2 "2013-05-27T11:26:56Z")

</div>

I'm also facing the same problem of retrieving the numbers of records when  
multiple records are deleted.

Is there any support for Elastic Search for this?

Any help will be greatly appreciated.

Thanks,  
Saurabh

On Sunday, May 26, 2013 10:00:41 AM UTC+5:30, Ankit Jain wrote:

> Hi All,
> 
> I executing query to delete records from ES, below is the code for the  
> same.
> 
> DeleteByQueryRequestBuilder dbqb = client  
> .prepareDeleteByQuery("index").setQuery(qb);
> 
> DeleteByQueryResponse deleteByQueryResponse = dbqb.execute()  
> .actionGet();
> 
> The query is working fine, but not returning the count of deleted records.
> 
> Please suggest some way through which we can find the number of deleted  
> records using the same query we used for deletion.
> 
> Thanks,  
> Ankit Jain

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [May 28, 2013, 10:24pm UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/3 "2013-05-28T22:24:21Z")

</div>

There is no support for this functionality because Lucene does not provide  
it.

Deleting a document in Lucene only marks a document as deleted in the index  
and it does not get purged until a merge occurs. The count is unknown until  
the merge actually happens.

--  
Ivan

On Mon, May 27, 2013 at 4:26 AM, Saurabh [saurabh113@gmail.com](mailto:saurabh113@gmail.com) wrote:

> I'm also facing the same problem of retrieving the numbers of records when  
> multiple records are deleted.
> 
> Is there any support for Elastic Search for this?
> 
> Any help will be greatly appreciated.
> 
> Thanks,  
> Saurabh
> 
> On Sunday, May 26, 2013 10:00:41 AM UTC+5:30, Ankit Jain wrote:
> 
> > Hi All,
> > 
> > I executing query to delete records from ES, below is the code for the  
> > same.
> > 
> > DeleteByQueryRequestBuilder dbqb = client  
> > .prepareDeleteByQuery("index")\*\*.setQuery(qb);
> > 
> > DeleteByQueryResponse deleteByQueryResponse = dbqb.execute()  
> > .actionGet();
> > 
> > The query is working fine, but not returning the count of deleted records.
> > 
> > Please suggest some way through which we can find the number of deleted  
> > records using the same query we used for deletion.
> > 
> > Thanks,  
> > Ankit Jain
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![hari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hari/32/1582_2.png) [@hari](https://discuss.elastic.co/u/hari)
#### Post date: [May 29, 2013, 12:36am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/4 "2013-05-29T00:36:24Z")

</div>

I'm wondering if this can be achieved by reading the "delete\_total" index  
status before and after your query  
E.g.  
curl -XGET '[http://localhost:9200/MyIndexName/\_stats/indexing?pretty=true](http://localhost:9200/MyIndexName/_stats/indexing?pretty=true)'

On Saturday, May 25, 2013 11:30:41 PM UTC-5, Ankit Jain wrote:

> Hi All,
> 
> I executing query to delete records from ES, below is the code for the  
> same.
> 
> DeleteByQueryRequestBuilder dbqb = client  
> .prepareDeleteByQuery("index").setQuery(qb);
> 
> DeleteByQueryResponse deleteByQueryResponse = dbqb.execute()  
> .actionGet();
> 
> The query is working fine, but not returning the count of deleted records.
> 
> Please suggest some way through which we can find the number of deleted  
> records using the same query we used for deletion.
> 
> Thanks,  
> Ankit Jain

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 29, 2013, 7:33am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/5 "2013-05-29T07:33:12Z")

</div>

My opinion is that it makes sense to get back the total number of deleted documents by a DeleteByQuery API call. Open an issue?

About counting deleted Lucene docs (stats), beware of nested docs. They will be counted as well...

My 2 cents

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 29 mai 2013 à 02:36, Hariharan Vadivelu [hariinfo@gmail.com](mailto:hariinfo@gmail.com) a écrit :

> I'm wondering if this can be achieved by reading the "delete\_total" index status before and after your query  
> E.g.  
> curl -XGET '[http://localhost:9200/MyIndexName/\_stats/indexing?pretty=true](http://localhost:9200/MyIndexName/_stats/indexing?pretty=true)'
> 
> On Saturday, May 25, 2013 11:30:41 PM UTC-5, Ankit Jain wrote:
> 
> > Hi All,
> > 
> > I executing query to delete records from ES, below is the code for the same.
> > 
> > DeleteByQueryRequestBuilder dbqb = client  
> > .prepareDeleteByQuery("index").setQuery(qb);
> > 
> > DeleteByQueryResponse deleteByQueryResponse = dbqb.execute()  
> > .actionGet();
> > 
> > The query is working fine, but not returning the count of deleted records.
> > 
> > Please suggest some way through which we can find the number of deleted records using the same query we used for deletion.
> > 
> > Thanks,  
> > Ankit Jain
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 29, 2013, 8:49am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/6 "2013-05-29T08:49:19Z")

</div>

## But, after digging a little more in source code, it sounds like Lucene does not provide it… ☹

David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 29 mai 2013 à 09:33, David Pilato [david@pilato.fr](mailto:david@pilato.fr) a écrit :

> My opinion is that it makes sense to get back the total number of deleted documents by a DeleteByQuery API call. Open an issue?
> 
> About counting deleted Lucene docs (stats), beware of nested docs. They will be counted as well...
> 
> My 2 cents
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 29 mai 2013 à 02:36, Hariharan Vadivelu [hariinfo@gmail.com](mailto:hariinfo@gmail.com) a écrit :
> 
> > I'm wondering if this can be achieved by reading the "delete\_total" index status before and after your query  
> > E.g.  
> > curl -XGET '[http://localhost:9200/MyIndexName/\_stats/indexing?pretty=true](http://localhost:9200/MyIndexName/_stats/indexing?pretty=true)'
> > 
> > On Saturday, May 25, 2013 11:30:41 PM UTC-5, Ankit Jain wrote:  
> > Hi All,
> > 
> > I executing query to delete records from ES, below is the code for the same.
> > 
> > DeleteByQueryRequestBuilder dbqb = client  
> > .prepareDeleteByQuery("index").setQuery(qb);
> > 
> > DeleteByQueryResponse deleteByQueryResponse = dbqb.execute()  
> > .actionGet();
> > 
> > The query is working fine, but not returning the count of deleted records.
> > 
> > Please suggest some way through which we can find the number of deleted records using the same query we used for deletion.
> > 
> > Thanks,  
> > Ankit Jain
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [May 29, 2013, 8:55am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/7 "2013-05-29T08:55:10Z")

</div>

First, fire up a count query  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/count/) and then fire  
the delete.  
You won't get an exact number under all circumstances, but if you can  
stop indexing/modification of the index for the time of the two  
operations, it will work as expected.

Jörg

Am 26.05.13 06:30, schrieb Ankit Jain:

> Please suggest some way through which we can find the number of  
> deleted records using the same query we used for deletion.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 6, 2017, 2:34am UTC](https://discuss.elastic.co/t/get-count-of-deleted-records-by-input-query/12123/8 "2017-07-06T02:34:10Z")

</div>


