# How to store only limited number of docs

**URL:** <https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067>\
**Category:** Elasticsearch\
**Created:** [April 6, 2018, 10:05am UTC](https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067 "2018-04-06T10:05:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [April 6, 2018, 10:05am UTC](https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067/1 "2018-04-06T10:05:02Z")

</div>

Hello -

I will be collecting data for every 10sec and hence my size of the particular index will be growing. Is there any way to limit the storage. I.e at any point of time i may require the latest 100 docs.count

---

<div class="post-metadata">

**Author:** ![mjunaidmuzammil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mjunaidmuzammil/32/56910_2.png) [@mjunaidmuzammil](https://discuss.elastic.co/u/mjunaidmuzammil)\
**Post date:** [April 6, 2018, 11:51am UTC](https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067/2 "2018-04-06T11:51:55Z")

</div>

You can use the rollover API in elasticsearch to restrict an index to a particular size. Once that limit is crossed, a new index will be created along with the alias. You can than safely remove the older index.

[https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-rollover-index.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-rollover-index.html)

I believe this is something which you were looking for.

---

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [April 6, 2018, 12:02pm UTC](https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067/3 "2018-04-06T12:02:47Z")

</div>

Yes, it matches but i still have few concrens

- if the size/count of docs reaches 1000/10mb then a new new alias is created with different name and all the docs will be moved to that allias\_new\_index. But i will doing some operation on existing\_index name so at a moment during the when new\_index created there will no docs in existing\_index any my operation fails? so how to handle this?  
I need to retain the existing\_name and at least latest 50~ docs so that any point of time, i will have the existing \_index and min of 50 docs to perform my operation.
-

---

<div class="post-metadata">

**Author:** ![kish](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kish](https://discuss.elastic.co/u/kish)\
**Post date:** [April 9, 2018, 5:06am UTC](https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067/4 "2018-04-09T05:06:37Z")

</div>

any clue ??

---

<div class="post-metadata">

**Author:** ![mjunaidmuzammil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mjunaidmuzammil/32/56910_2.png) [@mjunaidmuzammil](https://discuss.elastic.co/u/mjunaidmuzammil)\
**Post date:** [April 18, 2018, 7:17am UTC](https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067/5 "2018-04-18T07:17:12Z")

</div>

There are 2 operations expected for ES, i.e. Read & Write.

For Read operations, in order to retrieve data from old + new index, you can move with either of the solutions.

1. Use wild card indices while fetching data, so for the indices you can query the index **logs\_** \*.
2. Attach another read alias to multiple index, you need to issue index alias call here.

For Write operation, you should be using the newly attached alias from the rollover operation. Hope this answers to your question.

---

<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:** [May 16, 2018, 7:17am UTC](https://discuss.elastic.co/t/how-to-store-only-limited-number-of-docs/127067/6 "2018-05-16T07:17:15Z")

</div>

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