Multiple aliases for an index with the same filter


(Paavo Bennett) #1

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).


(David Pilato) #2

I think this should work.


(Paavo Bennett) #3

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?


(David Pilato) #4

No. I don't see any reason.

Could you provide a full recreation script as described in About the Elasticsearch category. 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.


(Paavo Bennett) #5

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?


(David Pilato) #6

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


(Paavo Bennett) #7

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.


(David Pilato) #8

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?


(system) closed #9

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