在弹性搜索模板运行时中为索引添加别名 [英] Adding alias to index in elastic search template runtime
问题描述
我想为Elasticsearch模板中的索引添加别名,但是别名并不总是固定的.它以客户ID开头.由于数据量大,我们将为每个客户端分别创建月度索引,我希望一个人从所有月度索引中查询数据.但是,由于每个客户端都有不同的索引,因此别名必须由clientId前缀.我该如何实现?
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?
例如:我的索引是:
client1_01_18_user_location/user_location
, client1_02_18_user_location/user_location
和
client2_01_18_user_location/user_location
, client2_02_18_user_location/user_location
在每个客户的情况下,一月份的数据将转到第一索引,而二月份的数据将转到第二索引.我希望根据要插入数据的客户端创建别名 client1_ul
或 client2_ul
.
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.
我该如何实现?
推荐答案
您可以使用POST这样解决:
You can solve with a POST like this:
POST /_aliases
{
"actions" : [
{ "add" : { "index" : "client1*", "alias" : "client1_ul" } }
]
}
此调用会将形式为client1 *的所有索引添加到别名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.
每个用户都需要一个POST.
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" : {}
}
}
通过这种方式,别名将在创建索引时由Elasticsearch自动添加到每个索引中.
In this way the alias will be added to each index at the index creation, automatically by elasticsearch.
这篇关于在弹性搜索模板运行时中为索引添加别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!