笔记二十五:使用 Search Template 和 Index Alias 
                                                    
                        
                    
                    
  
                    
                    Search Template - 解耦程序 & 搜索DSL
- Elasticsearch 的查询语句- 对相关性算分 / 查询性能都至关重要
 
- 在开发初期,虽然可以明确查询参数,但是往往还不能最终定义查询的DSL的具体结构- 通过Search Template 定义一个Contract
 
- 各司其职,解耦- 开发人员/搜索工程师/性能工程师
 
使用Search Template 进行查询
POST products/_search/template
{
  "id":"",
  "params": {
     "q":""
  }
}使用Index Alias 实现零停机运维
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "products", 
        "alias": "products_today"//为索引顶一个别名
      }
    }
  ]
}
//通过别名读写数据
PUT products_today/_doc/1
{
}使用Alias创建不同查询的视图
POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "movies-2019",
        "alias": "movies-lastest-highrate",
        "filter": {
          "range": {
            "rating": {
              "gte": 4
            }
          }
        }
      }
    }
  ]
}
POST movies-lastest-highrate/_search
{
  "query": {
    "match_all": {}
  }
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
 
           CrazyZard 的个人博客
 CrazyZard 的个人博客
         
           
           关于 LearnKu
                关于 LearnKu
               
                     
                     
                     粤公网安备 44030502004330号
 粤公网安备 44030502004330号