美文网首页
ElasticSearch搜索模版

ElasticSearch搜索模版

作者: 秦汉邮侠 | 来源:发表于2019-10-15 11:22 被阅读0次

构造数据

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搜索模版

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