# Multiple aliases for an index with the same filter

**URL:** <https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024>\
**Category:** Elasticsearch\
**Created:** [February 4, 2019, 8:50pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024 "2019-02-04T20:50:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliw00d](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@eliw00d](https://discuss.elastic.co/u/eliw00d)\
**Post date:** [February 4, 2019, 8:50pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/1 "2019-02-04T20:50:00Z")

</div>

Is it not possible to have multiple aliases for a single index where some might have the same filter criteria? I had an alias that needed to be renamed, but I wanted to keep the old one for backwards compatibility. However, after adding the new alias with the same filter, it does not have any documents associated with it (after reindexing).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 4, 2019, 9:23pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/2 "2019-02-04T21:23:02Z")

</div>

I think this should work.

---

<div class="post-metadata">

**Author:** ![eliw00d](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@eliw00d](https://discuss.elastic.co/u/eliw00d)\
**Post date:** [February 4, 2019, 9:59pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/3 "2019-02-04T21:59:03Z")

</div>

Hmm. The new aliases are there when I query \_aliases, and the filters are the same as the old aliases. When I \_search on the new aliases, I get 0 hits. But when I search on the old aliases, I get hits as expected.

Basically, I created a new index via the JavaScript API with a body that includes aliases and mappings. I then reindex from an old index to the new index.

Is there any reason the new alias filters did not work?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 5, 2019, 1:27am UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/4 "2019-02-05T01:27:07Z")

</div>

No. I don't see any reason.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![eliw00d](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@eliw00d](https://discuss.elastic.co/u/eliw00d)\
**Post date:** [February 5, 2019, 7:07pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/5 "2019-02-05T19:07:27Z")

</div>

It looks like this:

```
let newIndex = 'new_index'
let oldIndex = 'old_index'

let options = {
    index: newIndex,
    body: {
        aliases: {
            old_alias: {
                filter: {
                    term: {
                        key: 'value'
                    }
                }
            },
            new_alias: {
                filter: {
                    term: {
                        key: 'value'
                    }
                }
            }
        },
        mappings: {}
    }
}

let newIndexExists = await client.indices.exists({index: newIndex})
if (!newIndexExists) {
    await client.indices.create(options)

    await client.reindex({
        body: {
            source: {index: oldIndex},
            dest: {index: newIndex}
        }
    })
}

```

Basically, I create the new index if it doesn't exist and then reindex from old to new. Creating the index with aliases, mappings, and potentially settings should work but for some reason it doesn't. Is it maybe a bug with the JavaScript API?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 5, 2019, 7:22pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/6 "2019-02-05T19:22:12Z")

</div>

May be. Can you reproduce the problem with a Kibana Dev Console script?

---

<div class="post-metadata">

**Author:** ![eliw00d](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@eliw00d](https://discuss.elastic.co/u/eliw00d)\
**Post date:** [February 5, 2019, 8:13pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/7 "2019-02-05T20:13:59Z")

</div>

So, using Kibana I was able to get the reindex to work. I'm currently using elasticsearch 15.2.0 from npm, so I might try 15.3.1 and see if I run into the same issue.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 5, 2019, 8:37pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/8 "2019-02-05T20:37:47Z")

</div>

That can be a misusage of the JS client or a bug.  
Could you check what are the index settings after you execute your JS code?

---

<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 5, 2019, 8:37pm UTC](https://discuss.elastic.co/t/multiple-aliases-for-an-index-with-the-same-filter/167024/9 "2019-03-05T20:37:57Z")

</div>

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