【问题标题】:Elasticsearch: Create alias for template satisfying particular conditionElasticsearch:为满足特定条件的模板创建别名
【发布时间】:2019-06-07 04:42:51
【问题描述】:

定义索引模板时是否可以定义不同的别名。不同的别名将引用满足特定条件的索引名称。

例子:

{
   "index_patterns":[
      "*employee_records*"
   ],
   "settings":{
      "number_of_shards":3
   },
   "mappings":{
      "_doc":{
         "dynamic_templates":[
            // Dynamic Mapping
         ]
      }
   },
   "aliases":{
      "employee_records":{}
   }
}

假设我们创建了多个索引,例如

  • science_dept_employee_records_2015
  • science_dept_employee_records_2016
  • maths_dept_employee_records_2015
  • maths_dept_employee_records_2016

在定义索引模板时,这些索引都不存在。映射将保持不变。我想为上述场景定义两个别名science_dept_employee_records & maths_dept_employee_records

我能想到的一种方法是复制索引模板,以便有一个别名

 "index_patterns":[
      "maths_dept_employee_records*"
 ]

和另一个别名

 "index_patterns":[
      "science_dept_employee_records*"
 ]

但是,这会在多个模板中引入大量重复项。有没有更简洁的方法来实现这一点?

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    实现此目的的一种方法是使用multiple templates matching 并按如下顺序排列。

    一个模板定义了所有的映射和​​设置,并且具有最低的顺序(首先应用):

    {
       "index_patterns":[
          "*employee_records*"
       ],
       "order": 1,
       "settings":{
          "number_of_shards":3
       },
       "mappings":{
          "_doc":{
             "dynamic_templates":[
                // Dynamic Mapping
             ]
          }
       }
    }
    

    另一个模板定义了更高阶的maths_dept_employee 索引的别名,并在接下来应用:

    {
       "index_patterns":[
          "maths_dept_employee_records*"
       ],
       "order": 2,
       "aliases":{
          "maths_dept_employee_records":{}
       }
    }
    

    science_dept_employee 索引也是如此:

    {
       "index_patterns":[
          "science_dept_employee_records*"
       ],
       "order": 2,
       "aliases":{
          "science_dept_employee_records":{}
       }
    }
    

    【讨论】:

    • 是的。但在这种情况下,别名将如何映射?正如我所提到的,我希望别名 science_dept_employee_records 仅映射到 science_dept_employee_records*。数学也是如此。使用建议将所有别名映射到满足模式的所有索引
    • 啊!!使用 order 属性将有助于压倒一切.. 太好了。谢谢..我会试试的
    • 是的..它有效..谢谢..我已经对答案投了赞成票...看起来我忘记将其标记为“已接受的解决方案”..现在这样做了
    • 太棒了,很高兴它有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多