From b7ed36e1a0c59b4db5c50ba81a1279deac3b35ea Mon Sep 17 00:00:00 2001 From: Mantas <marc.mantas@gmail.com> Date: Tue, 12 Jul 2016 15:57:19 +0300 Subject: [PATCH] added documentation --- docs/Query/Template.md | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 docs/Query/Template.md diff --git a/docs/Query/Template.md b/docs/Query/Template.md new file mode 100644 index 0000000..949ef31 --- /dev/null +++ b/docs/Query/Template.md @@ -0,0 +1,69 @@ +# Template query + +> More info about Boosting query is in the [official elasticsearch docs][1] + +A query that accepts a query template and a map of key/value pairs to fill in template parameters. + +```JSON +{ + "query": { + "template": { + "inline": { "match": { "text": "{{query_string}}" }}, + "params" : { + "query_string" : "all about search" + } + } + } +} +``` + +And now the query via DSL: + +```php +$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: + +```yaml + +{ + "query": { + "template": { + "file": "my_template", + "params" : { + "query_string" : "all about search" + } + } + } +} + +``` + +And now the query via DSL: + +```php +$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(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-template-query.html -- GitLab