# How to update a document using index alias

**URL:** <https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866>\
**Category:** Elasticsearch\
**Created:** [June 9, 2017, 3:56pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866 "2017-06-09T15:56:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESCoder](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@ESCoder](https://discuss.elastic.co/u/ESCoder)\
**Post date:** [June 9, 2017, 3:56pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866/1 "2017-06-09T15:56:19Z")

</div>

Hi,

I have created an index "index-000001" with primary shards = 5 and replica = 1. And I have created two aliases

1. alias-read -\> index-000001
2. alias-write -\> index-000001

for indexing and searching purposes. When I do a rollover on alias-write when it reaches its maximum capacity, it creates a new "index-000002" and updates aliases as

1. alias-read -\> index-000001 and index-000002
2. alias-write -\> index-000002

How do I update/delete a document existing in index-000001(what if in case all I know is the document id but not in which index the document resides) ? I cannot use alias-write as it is pointing to the new index and I cannot use alias-read as it is pointing to multiple indices.

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 10, 2017, 8:18am UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866/2 "2017-06-10T08:18:39Z")

</div>

The rollover functionality is great when you have large amounts of immutable data, but if you need to update documents it will complicate things as you need to know the index name. Using rollover may therefore not be the ideal option for your use case, but if would be easier to give advice if you described your use case in more detail.

---

<div class="post-metadata">

**Author:** ![ESCoder](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@ESCoder](https://discuss.elastic.co/u/ESCoder)\
**Post date:** [June 12, 2017, 10:19pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866/3 "2017-06-12T22:19:44Z")

</div>

Hey @Christian_Dahlqvist,

I have a multi tenant application, instead of one index for all tenants and one index per tenant, we are going with the hybrid approach where one index is shared among few tenants.

Lets say I create an index "Index-000001" for tenants T1, T2, T3, T4, T5.  
In order to make indexing and searching easier, we were planning on creating

1. T1\_write, T1\_read
2. T2\_write, T2\_read
3. T3\_write, T3\_read
4. T4\_write, T4\_read
5. T5\_write, T5\_read  
aliases, all pointing to the same index. So while indexing a document belonging to T3, we use T3\_write alias.

Once the index reaches the max limit (lets say we dont want our indices to hold more than 1 Million documents), we want to create new index "Index-000002". And we thought of using index alias to rollover the index. And we update all our "\_write" indices to point to new index and update our "\_read" indices to point to both new and old index.

But if a document, existing in "Index-000001", gets modified, we cannot use Tx\_write alias to index the document as it points to the new index. If there were multiple old indices, how do I find out in which index my document resides ?

If the above aliasing structure isn't the right way, what would be a better way to architect our system?

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 13, 2017, 5:32am UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866/4 "2017-06-13T05:32:04Z")

</div>

> [@ESCoder](#):
>
> But if a document, existing in "Index-000001", gets modified, we cannot use Tx\_write alias to index the document as it points to the new index. If there were multiple old indices, how do I find out in which index my document resides ?

That is correct. You would first have to search for the document to identify in which index itv resides before updating directly against that index.

It is difficult to recommend a specific approach without knowing more about the use case. What type(s) of data are you indexing? How common are updates and/or deletes of this data compared to inserts of new data? How long is data kept in the cluster?

---

<div class="post-metadata">

**Author:** ![ESCoder](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@ESCoder](https://discuss.elastic.co/u/ESCoder)\
**Post date:** [June 13, 2017, 2:01pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866/5 "2017-06-13T14:01:38Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> What type(s) of data are you indexing?

We full text index regular documents (like word, pdf, etc) uploaded by the users

> [@Christian\_Dahlqvist](#):
>
> How common are updates and/or deletes of this data compared to inserts of new data?

updates/deletes are fairly common compared to inserts

> [@Christian\_Dahlqvist](#):
>
> How long is data kept in the cluster?

data is kept available forever for searching

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 13, 2017, 2:07pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866/6 "2017-06-13T14:07:04Z")

</div>

In this scenario a time-based or rollover index is not a natural fit in my opinion. Indices shared by a group of tenants might be a good approach as it means each tenant always have all documents in a single index, which makes it easy to update. The number of such shared indices, shards per index and tenants per index depends on the number of tenants as well as the expected data volumes.

---

<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 11, 2017, 2:07pm UTC](https://discuss.elastic.co/t/how-to-update-a-document-using-index-alias/88866/7 "2017-07-11T14:07:39Z")

</div>

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