What are aliases in elasticsearch for?

后端 未结 3 1167
挽巷
挽巷 2020-12-15 12:47

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

3条回答
  •  余生分开走
    2020-12-15 13:49

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

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

    And query like:

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

    and DELETE /logs_2018-01

提交回复
热议问题