Search Template
- 解耦程序和 DSL;
- 使得开发工程师、搜索工程师和性能工程师各司其职;
Search Template | 举几个栗子
Search Template | 创建 | 删除 | 查询
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
Search Template | 调用
POST tmdb/_search/template
{
"id":"tmdb",
"params": {
"q": "basketball with cartoon aliens"
}
}
Index Alias
Index Alias | 举几个栗子
Index Alias | 创建
- 为索引 movies-2019 取别名 movies-latest;
POST _aliases
{
"actions": [
{
"add": {
"index": "movies-2019",
"alias": "movies-latest"
}
}
]
}
创建 Index Alias 时设置 filters
POST _aliases
{
"actions": [
{
"add": {
"index": "movies-2019",
"alias": "movies-lastest-highrate",
"filter": {
"range": {
"rating": {
"gte": 4
}
}
}
}
}
]
}
通过 movies-lastest-highrate 查询文档
POST movies-lastest-highrate/_search
{
"query": {
"match_all": {}
}
}