elasticsearch高级功能系列之search template

四种search template方式: 

GET book/book/_search/template
{
  "file": "match_query",
  "params": {
    "field": "bookName.keyword",
    "value": "金明馆丛稿二编"
  }
}


GET book/book/_search/template
{
  "file":"match_tojson",
  "params": {
    "matchCondition":{
      "bookName.keyword":"金明馆丛稿二编"
    }
  }
}


GET book/book/_search/template
{
  "file":"match_join",
  "params": {
    "field":"bookName",
    "fields":["陈寅恪的最后20年","陈垣史源学杂文"]
  }
}


GET book/book/_search/template
{
  "file":"match_condition",
  "params": {
    "match_field":"bookAuthor",
    "match_value":"陈寅恪",
    "isCondition":true,
    "range_field":"bookPrice",
    "start":10,
    "end": 10
  }
}

 

以下4个模板文件放置在es安装目录config/scripts文件夹下,重启生效。

1、match_query.mustache文件:

{
    "query":{
      "match": {
         "{{field}}": "{{value}}{{^value}}王小波{{/value}}"
      }
  }
}


2、match_tojson.mustache文件:

{
    "query":{
      "match": {{#toJson}}matchCondition{{/toJson}}
      }
  }
}

3、match_join.mustache文件:

{
    "query":{
      "match": {
	     "{{field}}":"{{#join delimiter=','}}fields{{/join delimiter=','}}"
	  }
  }
}


4、match_condition.mustache文件:

{
    "query":{
      "match": {
             "{{match_field}}":"{{match_value}}"
	    }
      },
	  "post_filter":{
		{{#isCondition}}
			"range":{
				"{{range_field}}":{
				   {{#start}}
					  "gte":{{start}}
					   {{#end}},{{/end}}
				    {{/start}}
				   
				   {{#end}}
					   "lte":{{end}}
				   {{/end}}
				  }
				}
		
		{{/isCondition}}
	  
	  }
  }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值