当前位置:网站首页>What is the use of index aliases in ES
What is the use of index aliases in ES
2022-06-26 13:32:00 【Elastic open source community】
List of articles
1、 Alias (alias) What is it?
1.1 The official definition of
According to my habit , First give the official answer The index alias The definition of : An index alias is a secondary name used to reference one or more existing indexes . majority Elasticsearch API Accept index aliases instead of indexes .
1.2 Popular explanation
Official explanations are generally difficult to understand , This is especially true for people who have not touched or used it . Many online explanations say that the index alias is to protect the index , You can hide the index relative to the caller . In fact, this explanation can only be understood by people who understand what alias is , And those who understand it disdain to read it
In fact, the index alias is another name bound to the index , An alias can bind multiple indexes , An index can also be bound to multiple aliases . As for the function and significance of the index , I will use the following example to explain . Remember the conclusion first : Index aliases are very common 、 Very, very important .
2、 Alias (alias) What's the use
2.1 Analogy to the role of domain names
Before explaining the alias , Think about it first , What is the use of our common domain names ?
2.1.1 Than IP Good record
such as www.baidu.com, Than 110.242.68.4 Much easier to remember .
2.1.2 You can bind multiple IP Or applications
such as :
2.1.3 DNS Load balancing
Generally speaking , It is impossible for a web service to have only one server , It is a highly available cluster composed of multiple servers , High availability clusters often need to be load balanced , Such as Nginx、LVS etc. .
But with the increasing number of user requests , Load balancing also reaches the performance limit , It is necessary to solve the problem from the source , That is to say DNS distribution , Or call it DNS Load balancing .
that DNS How to forward the request ? Let's take a look at how a user's request is sent to the server 
Suppose the server of a website is in Beijing , So users in Shanghai want to get the data on the server , It takes a long distance , Due to transmission speed, routing and forwarding, etc , It will cause the access speed to be very slow .
Therefore, many large Internet companies will deploy multiple data centers nationwide or even worldwide , Users in different regions only need to DNS Forward user request , Visit nearby , In this way, the speed increases a lot . This process is from the source of the user request 
such as , When I am from where I am ( Beijing ) When visiting Baidu's domain name ,DNS Point to me IP The address is :110.242.68.4
When I access Baidu domain name from a remote host , Of the returned result IP The address is different .
2.2 The function of aliases
2.2.1 Hide the underlying index
Understand the role of domain name , Alias is easy to explain , stay ES in , The function of index alias is very similar to that of domain name , Aliases can be bound to multiple indexes , The client can call the index by calling the alias , In this way, if all changes in the underlying index are imperceptible to the user . The caller does not know which indexes the index alias refers to , And don't care .
2.2.2 Encapsulated filter
For example, the following code pairs the index test Created two aliases , among , When calling alias_2 When executing a query on an index , The filter that will automatically execute the do not hit
PUT /test
{
"aliases": {
"alias_1": {
},
"alias_2": {
"filter": {
"term": {
"user.id": "kimchy" }
}
}
}
}
When an index often needs to execute certain specific queries , You can define... In this way . For example, yes. person The index defines three aliases , People of different ages can be queried without adding any query criteria :
- person_lt_18
- person_lt_30
- person_gte_30
3、 Alias (alias) Where to use : Use scenarios
3.1 Scroll index

3.2 Index template / Component template
PUT _index_template/my_template
{
"index_patterns": ["test_ilm_index_*"],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"index.lifecycle.name": "test_ilm"
}
}
}
3.3 Data flow
Convert index aliases to data streams
POST /_data_stream/_migrate/<alias>
4、 Alias (alias) How to use it?
4.1 grammar
POST /_aliases
4.2 Basic usage
4.2.1 Add an alias to the index
to product Add alias product_template
POST _aliases
{
"actions" : [
{
"add" : {
"index" : "product", "alias" : "product_template" } }
]
}
4.2.2 Alias the index
hold product Rename the alias of to product_real ( Atomic manipulation )
POST /_aliases
{
"actions" : [
{
"remove" : {
"index" : "product", "alias" : "product_template" } },
{
"add" : {
"index" : "product", "alias" : "product_real" } }
]
}
4.2.3 Unbind alias for index
Delete product Another name for product_real
POST /_aliases
{
"actions" : [
{
"remove" : {
"index" : "product", "alias" : "product_real" } }
]
}
4.2.4 Bind multiple aliases
One alias binds to multiple indexes
POST /_aliases
{
"actions" : [
{
"add" : {
"index" : "product", "alias" : "product_real2" } },
{
"add" : {
"index" : "product2", "alias" : "product_real2" } }
]
}
4.2.5 Bind alias when defining index
Specify alias when defining index mapping
PUT /test
{
"aliases": {
"alias_1": {
},
"alias_2": {
"filter": {
"term": {
"user.id": "kimchy" }
}
}
}
}
4.2.6 As field type
PUT trips
{
"mappings": {
"properties": {
"distance": {
"type": "long"
},
"route_length_miles": {
"type": "alias",
"path": "distance"
},
"transit_mode": {
"type": "keyword"
}
}
}
}
GET _search
{
"query": {
"range" : {
"route_length_miles" : {
"gte" : 39
}
}
}
}
边栏推荐
- 7-2 picking peanuts
- Stack, LIFO
- Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >
- Beifu realizes the control of time slice size and quantity through CTU and ton
- Update and download of Beifu EtherCAT XML description file
- C - Common Subsequence
- [how to connect the network] Chapter 2 (middle): sending a network packet
- 2. Introduction to parallel interface, protocol and related chips (8080, 8060)
- 适配器模式(Adapter)
- 7-1 range of numbers
猜你喜欢

Log in to the server using SSH key pair

Arcpy -- use of insertlayer() function: adding layers to map documents

ES中索引别名(alias)的到底有什么用

Basic methods for network diagnosis and hardware troubleshooting of Beifu EtherCAT module

There are many contents in the widget, so it is a good scheme to support scrolling

What features are added to Photoshop 2022 23.4.1? Do you know anything

Adapter mode

Use of wangeditor rich text editor

MySQL讲解(二)

Fire warning is completed within 10 seconds, and Baidu AI Cloud helps Kunming Guandu build a new benchmark of smart city
随机推荐
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
Guruiwat rushed to the Hong Kong stock exchange for listing: set "multiple firsts" and obtained an investment of 900million yuan from IDG capital
H5视频自动播放和循环播放
HDU 3555 Bomb
Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏
嵌入式virlog代码运行流程
MySQL数据库常见故障——遗忘数据库密码
MySQL数据库讲解(六)
IDC report: the AI cloud market share of Baidu AI Cloud ranks first for six consecutive times
Zoomeeper sets ACL permission control (only specific IP access is allowed to enhance security)
Mysql database explanation (V)
7-1 n queen problem
输入文本自动生成图像,太好玩了!
创建一个自己的跨域代理服务器
组合模式(Composite )
Fire warning is completed within 10 seconds, and Baidu AI Cloud helps Kunming Guandu build a new benchmark of smart city
Decorator
5+api, clear application cache
Analysis of state transition diagram of Beifu NC axis
A primary multithreaded server model