当前位置:网站首页>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
}
}
}
}
边栏推荐
猜你喜欢
MariaDB study notes
12 SQL optimization schemes summarized by old drivers (very practical)
NVM installation tutorial
Teacher Li Hang's new book "machine learning methods" is on the market! Purchase link attached
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
MySQL explanation (I)
Input text to automatically generate images. It's fun!
First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology
[how to connect the network] Chapter 2 (middle): sending a network packet
Use of wangeditor rich text editor
随机推荐
2. Introduction to parallel interface, protocol and related chips (8080, 8060)
Here document interaction free and expect automatic interaction
MongoDB系列之适用场景和不适用场景
Here Document免交互及Expect自动化交互
Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital
awk工具
A few lines of code can realize complex excel import and export. This tool class is really powerful!
Script - crawl the customized storage path of the cartoon and download it to the local
【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
IDC report: the AI cloud market share of Baidu AI Cloud ranks first for six consecutive times
MySQL explanation (I)
Uva10341 solve it
Some conclusions about Nan
May product upgrade observation station
I - Dollar Dayz
Adapter mode
泰山OFFICE技术讲座:使用字体粗体的四种情形
Electron official docs series: Contributing
【Spark】. Explanation of several icons of scala file in idea
Mysql database explanation (6)