Basically, both query and search template achieve the same results. The
difference is in the "how" they achieve it.
Search template separates the search template from the search request. The
search template is stored once under the .script index, and all the search
request reference the template name and provide value binding for the
template. The search template allows you to save bandwidth.
In the query tamplate you send both the template and value binding in the
same request. It consumes more bandwidth, but doesn't require you to store
anything on ES before sending the request.
Example:
PUT blogs/post/1
{
"title": "title1",
"desc": "desc1",
"visible": true
}
PUT blogs/post/2
{
"title": "title2",
"desc": "desc2",
"visible": false
}
PUT blogs/post/3
{
"title": "title2",
"desc": "desc2",
"visible": true
}
Template query
GET /blogs/post/search
{
"query": {
"template": {
"query": {
"filtered": {
"query": {
"match{{template}}": {}
},
"filter": {
"bool": {
"must": {
"term": {
"visible": "{{visible}}"
}
}
}
}
}
},
"params" : {
"template": "all",
"visible": true
}
}
}
}
Search template
Store the tamplate under .scripts index
POST /search/template/query_template
{
"query": {
"filtered": {
"query": {
"match{{template}}": {}
},
"filter": {
"bool": {
"must": {
"term": {
"visible": "{{visible}}"
}
}
}
}
}
}
}
Run the query
GET /blogs/post/_search/template
{
"template": {
"id": "query_template"
},
"params" : {
"template": "all",
"visible": true
}
}
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5811dc41-3b41-485f-994a-80facd80ab03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.