GET /car_shop/cars/_search
GET /car_shop/cars/_search/template
{
"inline" : {
"query" : {
"match" : {
"{{field}}" : "{{value}}"
}
}
},
"params": {
"field" : "brand",
"value" : "宝马"
}
}
GET /car_shop/cars/_search/template
{
"inline" : "{\"query\" : {\"match\" : {{#toJson}}matchCondition{{/toJson}}}}",
"params" : {
"matchCondition" : {
"brand" : "宝马"
}
}
}
GET /car_shop/cars/_search/template
{
"inline" : {
"query" : {
"match" : {
"brand" : "{{#join delimiter=','}}brands{{/join delimiter=','}}"
}
}
},
"params": {
"brands" : ["宝马","奔驰"]
}
}
GET /car_shop/cars/_search/template
{
"inline" : {
"query" : {
"range" : {
"price" : {
"gt" : "{{start}}",
"lt" : "{{end}}{{^end}}330000{{/end}}"
}
}
}
},
"params": {
"start" : 30000,
"end" : 360000
}
}
GET /car_shop/cars/_search/template
{
"file" : "car_shop_query",
"params": {
"car_brand" : "宝马",
"price_bool" : true,
"start" : 120000,
"end" : 370000
}
}
GET /car_shop/cars/_search/template
{
"file" : "car_shop_query",
"params": {
"car_brand" : "宝马",
"price_bool" : false
}
}
script下的脚本
{
"query" : {
"bool":{
"must" : [
{"match" : {
"brand" : "{{car_brand}}"
}}
],
"filter":{
{{#price_bool}}
"range":{
"price" : {
"gte" : "{{start}}",
"lte" : "{{end}}"
}
}
{{/price_bool}}
}
}
}
}