# How to keep segment count of active index small?

**URL:** <https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375>\
**Category:** Elasticsearch\
**Created:** [February 24, 2017, 9:40am UTC](https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375 "2017-02-24T09:40:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [February 24, 2017, 9:40am UTC](https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375/1 "2017-02-24T09:40:42Z")

</div>

We have a index contains around 1 million documents, each time after the full re-indexing, the segment count of each shard is general around 20-30.

And we found that if we optimize the index (\_forcemerge?max\_num\_segments=1), the query performance could be significantly improved.

But after the full re-index, the segment count increased to 20 - 30 again.

So my question is, is there a way to keep the max segment count to be a low number during the re-indexing?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 24, 2017, 9:45am UTC](https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375/2 "2017-02-24T09:45:34Z")

</div>

No there's not. You can run a `_forcemerge` after the indexing though.

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [February 24, 2017, 9:54am UTC](https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375/3 "2017-02-24T09:54:36Z")

</div>

I heard that it is not recommended to to \_forcemerge on active index, is it true?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 24, 2017, 10:02am UTC](https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375/4 "2017-02-24T10:02:50Z")

</div>

Yes, which is why I said after 🙂

If you are having problems with search speed during index time, perhaps telling us more about your use case will open up some ideas on other options.

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [February 24, 2017, 10:26am UTC](https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375/5 "2017-02-24T10:26:10Z")

</div>

Thanks!

We do have a query perf issue which I asked in another topic:

> [@ES query performance when searching on filed with wildcard in field name](https://discuss.elastic.co/t/es-query-performance-when-searching-on-filed-with-wildcard-in-field-name/75658):
>
> I saw significant performance difference between searching on field with exact field name and searching on field with wildcard suffix i name. Following is my mapping: PUT /myindex { "mappings": { "docs": { "Locale": { "type": "text", "fields": { "lowercaseraw": { "type": "text", "analyzer": "lowercase\_keyword" } }, "analyzer": "standard" }, …

Could you please take a look?

---

<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:** [March 24, 2017, 10:26am UTC](https://discuss.elastic.co/t/how-to-keep-segment-count-of-active-index-small/76375/6 "2017-03-24T10:26:19Z")

</div>

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