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

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.

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.

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"
}
}
}
}
}
}
]
}

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.

1 Like

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