四种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}}
}
}
}