ElasticSearch搜索模版

构造数据

PUT twiter/doc/1 
{
   "title":"search for these words"  
}

PUT book/doc/1 
{
   "title":"search for these words"  
}

注册模版

POST _scripts/twitertemplate
{
    "script": {
        "lang": "mustache",
        "source": {
            "query": {
                "match": {
                    "title": "{{query_string}}"
                }
            }
        }
    }
}

使用模版

  • 在指定索引中搜索
GET twiter/_search/template/
{
    "id": "twitertemplate", 
    "params": {
        "query_string": "search for these words"
    }
}
  • 在所有索引中搜索
GET _search/template/
{
    "id": "twitertemplate", 
    "params": {
        "query_string": "search for these words"
    }
}

你可能感兴趣的:(ElasticSearch搜索模版)