elasticsearch中的别名是什么? [英] What are aliases in elasticsearch for?

查看:133
本文介绍了elasticsearch中的别名是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在一家使用Elasticsearch的公司工作。尽管它的大多数概念与关系数据库有些相似,并且我能够理解它们,但我仍然不太了解别名的概念。

I recently started working in a company that uses Elasticsearch. While most of its concepts are somewhat similar to relational databases and I am able to understand them, I still don't quite get the concept of aliases.

我没有找到任何此类问题,以及 Elasticsearch网站也无济于事。

I did not find any such question here and the information provided on the Elasticsearch website did not help much either.

有人可以解释别名的含义,理想情况下还包括需要使用别名的示例吗?

Can someone explain what aliases are for and ideally include an example of a situation where they are needed?

推荐答案

@arhak很好地涵盖了该主题。
(至少)使我理解索引的价值的一个用例是需要删除过时的文档,更具体地说是在使用基于时间的索引

@arhak covered the topic pretty well. One use case that (at least) made me understand the value of indices was the need to remove out-of-date documents and more specifically when using time-based-indices.

例如,您需要将应用程序的日志保存至少一年。您决定使用基于时间的索引,这意味着您将使用以下格式保存到索引中: 2018-02-logs,2018-03-logs 等。为了能够在您创建以下别名的每个索引中进行搜索:

For example, you need to keep the logs of an application for at least one year. You decide to use time-based-indices, meaning you save into indices with the following format: 2018-02-logs, 2018-03-logs etc.. In order to be able to search in every index you create the following alias:

POST /_aliases
{
 "actions": [{ 
     "add": {
          "alias": "current-logs", "indices": [ "2018-02-logs","2018-03-logs" ]
        }  
  }]
}

然后查询如下:

GET /current-logs/_search

另一个优点是您可以轻松删除过时的值:

Another advantage is that you can delete the out-of-date values very easily:

POST /_aliases
{
  "actions": [

      { "remove": { "alias": "current-logs",  "index": "logs_2018-01" }}
  ]
}

DELETE / logs_2018 -01

这篇关于elasticsearch中的别名是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆