一、 Search Template 实现程序和搜索DSL的解耦
在开发初期,虽然可以明确查询参数,但是往往还不能最终确定查询的DSL的具体结构。通过Search Template定义一个Contract,让程序开发人员与搜索工程师、性能工程师各司其职,解耦
- 定义 Search Template
DELETE _scripts/tmdb
GET _scripts/tmdb
POST _scripts/tmdb
{
"script": {
"lang": "mustache",
"source": {
"_source": [
"title","overview"
],
"size": 20,
"query": {
"multi_match": {
"query": "{{q}}",
"fields": ["title","overview"]
}
}
}
}
}
- 使用Search Template
POST tmdb/_search/template
{
"id":"tmdb",
"params": {
"q": "basketball with cartoon aliens"
}
}
二、 Index Alias 给索引起别名 ----- 实现零停机运维
image.png- 使用
POST movies-latest/_search
{
"query": {
"match_all": {}
}
}
使用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": {}
}
}
网友评论