# Is there a way to read from only the index set as write index

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-read-from-only-the-index-set-as-write-index/357135>\
**Category:** Elasticsearch\
**Created:** [April 10, 2024, 11:29am UTC](https://discuss.elastic.co/t/is-there-a-way-to-read-from-only-the-index-set-as-write-index/357135 "2024-04-10T11:29:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maitri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maitri/32/123992_2.png) [@Maitri](https://discuss.elastic.co/u/Maitri)\
**Post date:** [April 10, 2024, 11:29am UTC](https://discuss.elastic.co/t/is-there-a-way-to-read-from-only-the-index-set-as-write-index/357135/1 "2024-04-10T11:29:23Z")

</div>

Hi,  
I have created two index with the same alias, Index1 and Index2. Current live data goes into Index1. The reason for creating index2 is I am developing a feature and when it is released I want to remove Index1 and switch alias to Index2. So, for now I have set is\_write\_index to true for Index1. But, I also want to read the data for now from Index1 only as Index2 related features are under development. Can anyone please guide me on how I can achieve this?

FYI: For reading only from the index to which I am writing to, I tried one of the article from Stack overflow which mentioned to add a filter on the field that must exist in the write index, but it didn't work.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 10, 2024, 12:34pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-read-from-only-the-index-set-as-write-index/357135/2 "2024-04-10T12:34:56Z")

</div>

If you are using an alias to search, it will search on all indices that have those alias.

If you want to exclude one index, you need to filter your query using some field that would exist on only one of the index.

It is not clear what you tried because you didn't share.

---

<div class="post-metadata">

**Author:** ![Maitri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maitri/32/123992_2.png) [@Maitri](https://discuss.elastic.co/u/Maitri)\
**Post date:** [April 10, 2024, 1:40pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-read-from-only-the-index-set-as-write-index/357135/3 "2024-04-10T13:40:16Z")

</div>

I applied a filter at the time of adding an alias like the following, but it didn't work and the search is being performed on both the index:

> {  
> "actions" : [  
> {  
> "add" : {  
> "index" : "index2",  
> "alias" : "test"  
> }  
> }, {  
> "add" : {  
> "index" : "index1",  
> "alias" : "test",  
> "is\_write\_index" : true,  
> "filter": {  
> "bool": {  
> "must": {  
> "exists": {  
> "field": "field1"  
> }  
> }  
> }  
> }  
> }  
> }  
> ]  
> }

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 10, 2024, 1:59pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-read-from-only-the-index-set-as-write-index/357135/4 "2024-04-10T13:59:33Z")

</div>

You created a filtered alias.

Your current alias will show **everything** from `index2` and from `index1` it will only shows the documents that have the `field1`.

It is not sure why you need to keep `index2` in the alias if you just want to read data from `index1`, why not remove the alias?

it is not clear what exactly you want to approach and why you are using alias, the alias should be used when you want to query multiple indices using the same alias, you want the oposite of this.

---

<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 8, 2024, 1:59pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-read-from-only-the-index-set-as-write-index/357135/5 "2024-05-08T13:59:56Z")

</div>

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