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

查看:27
本文介绍了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天全站免登陆