如何使用logstash在两个索引上创建别名? [英] How to create an alias on two indexes with logstash?

查看:794
本文介绍了如何使用logstash在两个索引上创建别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在研究的集群中,有两个主要索引,比如indexAindexB,但是这两个索引每天都有索引,因此通常我有indexA-{+YYYY.MM.dd}indexB-{+YYYY.MM.dd}.

In the cluster that I am working on there are two main indexes, let's say indexA and indexB but these two indexes are indexed each day so normaly I have indexA-{+YYYY.MM.dd} and indexB-{+YYYY.MM.dd}.

我想要的是拥有一个别名,该别名将indexA-{+YYYY.MM.dd}indexB-{+YYYY.MM.dd}聚集在一起并命名为alias-{+YYYY.MM.dd}.

What I want is to have one alias that gathers indexA-{+YYYY.MM.dd} and indexB-{+YYYY.MM.dd} together and named alias-{+YYYY.MM.dd}.

有人知道如何使用logstash在一个别名中收集两个索引吗?

Does anyone know how to gather two indexes in one alias with logstash ?

提前谢谢

推荐答案

据我所知,无法直接用logstash做到这一点.您可以使用elasticsearch API在外部程序中完成此操作: http://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/indices-aliases.html

As far as I know, there's no way to do it with logstash directly. You can do it from an external program using the elasticsearch API: http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html

例如:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        { "add" : { "index" : "indexA-2015.01.01", "alias" : "alias-2015.01.01" } },
        { "add" : { "index" : "indexB-2015.01.01", "alias" : "alias-2015.01.01" } }
    ]
}'

另一种选择(不符合将其命名为alias-yyyy.mm.dd的要求)是使用索引模板,该模板在创建索引时会自动添加别名.

The other option (which doesn't meet your requirements of having it named alias-yyyy.mm.dd) is to use an index template that automatically adds an alias when the index is created.

请参见 http://www.elastic.co /guide/en/elasticsearch/reference/current/indices-templates.html :

curl -XPUT localhost:9200/_template/add_alias_template -d '{
  "template" : "index*",
  "aliases" : {
    "alias" : {}
    }
  }
}'

这会将alias的别名添加到每个名为index *的索引中.

This will add the alias of alias to every index named index*.

然后您可以针对别名进行所有查询.您可以在Kibana中将该别名设置为索引,然后一切正常.

You can then do all of your queries against alias. You can setup that alias in Kibana as an index and things will just work right.

这篇关于如何使用logstash在两个索引上创建别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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