美文网首页
【elasticsearch】19、使用search templ

【elasticsearch】19、使用search templ

作者: cutieagain | 来源:发表于2020-03-17 23:30 被阅读0次

search template - 解耦程序&搜索dsl

  • elasticsearch的查询语句
    • 对相关性算分 / 查询性能都至关重要
  • 在发开发初期,虽然可以明确查询参数,但是往往还不能最终定义查询的dsl的具体结构
    • 通过search tamplate定义一个contract
  • 各司其职,解耦
    • 开发人员/搜索工程师/性能工程师


      image.png

index alias实现零停机运维

  • 实现索引的冲减,前端可以不间断对索引进行查询


    image.png
    image.png
POST _scripts/tmdb
{
  "script": {
    "lang": "mustache",
    "source": {
      "_source": [
        "title","overview"
      ],
      "size": 20,
      "query": {
        "multi_match": {
          "query": "{{q}}",
          "fields": ["title","overview"]
        }
      }
    }
  }
}
DELETE _scripts/tmdb

GET _scripts/tmdb

POST tmdb/_search/template
{
    "id":"tmdb",
    "params": {
        "q": "basketball with cartoon aliens"
    }
}


PUT movies-2019/_doc/1
{
  "name":"the matrix",
  "rating":5
}

PUT movies-2019/_doc/2
{
  "name":"Speed",
  "rating":3
}

POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "movies-2019",
        "alias": "movies-latest"
      }
    }
  ]
}

POST movies-latest/_search
{
  "query": {
    "match_all": {}
  }
}

POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "movies-2019",
        "alias": "movies-lastest-highrate",
        "filter": {
          "range": {
            "rating": {
              "gte": 4
            }
          }
        }
      }
    }
  ]
}

POST movies-lastest-highrate/_search
{
  "query": {
    "match_all": {}
  }
}

相关文章

网友评论

      本文标题:【elasticsearch】19、使用search templ

      本文链接:https://www.haomeiwen.com/subject/eklfyhtx.html