How to create an alias on two indexes with logstash?

只谈情不闲聊 提交于 2019-12-12 16:20:58

问题


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}.

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}.

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

Thank you in advance


回答1:


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

For example:

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" } }
    ]
}'

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.

See 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" : {}
    }
  }
}'

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

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.



来源:https://stackoverflow.com/questions/29941296/how-to-create-an-alias-on-two-indexes-with-logstash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!