1

I want to add an alias to the index in elasticsearch template, but the alias is not always fixed. Its prepended by a client id. Due to the size of the data, we are creating monthly indexes for each client separately, and I want a single to query the data from all monthly indexes. However, because each client has different indexes, the alias has to prepended by clientId. How can I achieve this?

Eg: my indexes are:

client1_01_18_user_location/user_location, client1_02_18_user_location/user_location

and

client2_01_18_user_location/user_location, client2_02_18_user_location/user_location

The data for the month of January goes to 1st index, and for Feb goes to 2nd index in each client's case. I want an alias client1_ul or client2_ul to be created, based on, for which client the data is being inserted.

How do I achieve this?

2
  • I did not fully understand your question. You can easily create an alias for existing index with PUT /client1_01_18_user_location/_alias/client1_ul. Is there some problem with this approach? Commented Mar 28, 2018 at 18:29
  • No. But because, these are monthly indexes, and I do not want someone to keep an eye on creating monthly indexes before the data is written to the index, I want to register a template which creates the index with a prefined mapping and alias, anytime, the index is not found, while writing the data. Commented Mar 28, 2018 at 20:12

1 Answer 1

4

You can solve with a POST like this:

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "client1*", "alias" : "client1_ul" } }
    ]
}

This call will add all the index of the form client1* to the alias client1_ul, that can be used to query all the months.

You will need a POST for each user.

Otherwise, you can use a index template for each client, if not all the indexes are present when you add the alias. The template can provide an alias:

PUT _template/template_1
{
    "index_patterns" : ["client1*"],
    "mappings" : {
        ... optional
    },
    "aliases" : {
        "client1_ul" : {}
    }
}

In this way the alias will be added to each index at the index creation, automatically by elasticsearch.

Sign up to request clarification or add additional context in comments.

1 Comment

But there are other indexes in the system too, that start with client1_, and are not monthly indexes, so I can't do it like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.