ElasticSearch搜索模版

2019-10-15  本文已影响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"
    }
}
上一篇下一篇

猜你喜欢

热点阅读