Template query
More info about Boosting query is in the official elasticsearch docs
A query that accepts a query template and a map of key/value pairs to fill in template parameters.
{
"query": {
"template": {
"inline": { "match": { "text": "{{query_string}}" }},
"params" : {
"query_string" : "all about search"
}
}
}
}
And now the query via DSL:
$template = '"match": { "text": "{{query_string}}"';
$params = ['query_string' => 'all about search'];
$templateQuery = new TemplateQuery();
$templateQuery->setInline($template);
$templateQuery->setParams($params);
$search = new Search();
$search->addQuery($templateQuery);
$queryArray = $search->toArray();
The template of the query can also be stored in a different file, that way, the file path must
be provided in stead of inline
parameter:
{
"query": {
"template": {
"file": "my_template",
"params" : {
"query_string" : "all about search"
}
}
}
}
And now the query via DSL:
$params = ['query_string' => 'all about search'];
$templateQuery = new TemplateQuery();
$templateQuery->setFile('my_template');
$templateQuery->setParams($params);
$search = new Search();
$search->addQuery($templateQuery);
$queryArray = $search->toArray();