# The problem of a lot of deleted docs?

**URL:** <https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241>\
**Category:** Elasticsearch\
**Created:** [October 18, 2016, 4:23am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241 "2016-10-18T04:23:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)\
**Post date:** [October 18, 2016, 4:23am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/1 "2016-10-18T04:23:21Z")

</div>

I need to delete docs frequent,but `es` only flags these as deleted.If there are a lot of deleted docs,the speed of query will lower?And has other problems?

---

<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:** [October 18, 2016, 5:32am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/2 "2016-10-18T05:32:43Z")

</div>

Depending on the use case you can:

- do nothing else. At some point elasticsearch will eventually remove deleted docs.
- run a force merge
- index in a new index and remove the old one
- use index name pattern such as time based indices with index-DDMMYYY and remove old data by removing old indices (you can use curator for that)

May be describe more what is the use case?

---

<div class="post-metadata">

**Author:** ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)\
**Post date:** [October 19, 2016, 2:03am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/3 "2016-10-19T02:03:26Z")

</div>

I use `es` to save member info(about 100 million docs),and often need to delete member info(doc).

I find the number of `deleted` docs grow fast,Which moment `es` will remove deleted docs,if i never use `force merge` api ,i will have query performance issues after a period of time?

---

<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:** [October 19, 2016, 2:25am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/4 "2016-10-19T02:25:48Z")

</div>

It'll pick up and merge those deleted documents asynchronously, whenever it feels like it has enough work to do. For the most part deleted documents are just a thing you have to live with if you have an index that you are constantly updating or being deleted. They have very little CPU overhead which should be fine. They cost disk space and proportional IO bandwidth.

What proportion of deleted documents to live documents do you have now?

---

<div class="post-metadata">

**Author:** ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)\
**Post date:** [October 19, 2016, 2:43am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/5 "2016-10-19T02:43:49Z")

</div>

Now i have 5% deleted docs,i think i will have 30% - 40% deleted docs..

If it cost `proportional IO bandwidth`,i think i will have query performance issues?

I tried 'force merge',but the number of deleted docs just from 5 million to 3 million,I can clear the deleted docs?

---

<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:** [October 19, 2016, 4:58am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/6 "2016-10-19T04:58:51Z")

</div>

Note that when you update a document you basically delete and reindex.

Did you see any slowness issue? I mean that it's often better letting elasticsearch do his job.  
It will eventually remove deleted docs when needed.

---

<div class="post-metadata">

**Author:** ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)\
**Post date:** [October 19, 2016, 6:16am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/7 "2016-10-19T06:16:25Z")

</div>

Thank you,i haven't seen any slowness issue until now,i just worry about what will happen someday in the future.

I use `_stats` to find there are `3212174` deleted docs.But after i use `index/_forcemerge?only_expunge_deletes=true` api,it still have `3065150` deleted docs.

Before:

```auto
"primaries": {
     "docs": {
          "count": 74090335,
          "deleted": 3212174
 }

```

After:

```auto
"docs": {
  "count": 74090878,
  "deleted": 3065150
}

```

---

<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:** [October 19, 2016, 9:08am UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/8 "2016-10-19T09:08:42Z")

</div>

> [@famoss](#):
>
> Thank you,i haven't seen any slowness issue until now,i just worry about what will happen someday in the future.

Well. I'm always saying something like "don't try to fix issues you don't have".  
Monitor things is a great thing but let elasticsearch does its jobs.

Unless you want to reindex more than 50% of your docs at once, stick with the default behavior.  
It has proven to work well for years. At least on projects I was managing before joining elastic.

> [@famoss](#):
>
> But after i use index/\_forcemerge?only\_expunge\_deletes=true api,it still have 3065150 deleted docs.

Yes. The "problem" here (which is not a problem) is that you probably have more than one segment. You need to tell elasticsearch to write only one segment `max_num_segments =1`.  
But again, it's probably a bad idea to run that often. Elasticsearch is smart enough to know what is the best number of segments you should have.

Unless it's a logging use case but here it's not the case.

---

<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 5, 2017, 10:11pm UTC](https://discuss.elastic.co/t/the-problem-of-a-lot-of-deleted-docs/63241/9 "2017-07-05T22:11:22Z")

</div>


