forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring to allow for non quoted templates.
As per suggestion in elastic#4879 modified the implementation to allow for templates that are not quoted but legitimate json. Leaving the option to completely quote in - needed anyway for support for referencing templates stored in the config directory. Relates to elastic#4879
- Loading branch information
Isabel Drost-Fromm
committed
Feb 14, 2014
1 parent
e1806a9
commit 21903db
Showing
7 changed files
with
165 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[[query-dsl-template-query]] | ||
=== Template Query | ||
|
||
A query that accepts a query template and a map of key/value pairs to fill in | ||
template parameters. | ||
|
||
[source,js] | ||
------------------------------------------ | ||
GET _search | ||
{ | ||
"query": { | ||
"template": { | ||
"query": {"match_{{template}}": {}}, | ||
"params" : { | ||
"template" : "all" | ||
} | ||
} | ||
} | ||
} | ||
------------------------------------------ | ||
|
||
|
||
Alternatively escaping the template works as well: | ||
|
||
[source,js] | ||
------------------------------------------ | ||
GET _search | ||
{ | ||
"query": { | ||
"template": { | ||
"query": "{\"match_{{template}}\": {}}\"", | ||
"params" : { | ||
"template" : "all" | ||
} | ||
} | ||
} | ||
} | ||
------------------------------------------ | ||
|
||
You register a template by storing it in the conf/scripts directory of | ||
elasticsearch. In order to execute the stored template reference it in the query parameters: | ||
|
||
|
||
[source,js] | ||
------------------------------------------ | ||
GET _search | ||
{ | ||
"query": { | ||
"template": { | ||
"query": "storedTemplate", | ||
"params" : { | ||
"template" : "all" | ||
} | ||
} | ||
} | ||
} | ||
------------------------------------------ | ||
|
||
|
||
Templating is based on Mustache. Substitution of tokens works as follows: | ||
|
||
|
||
[source,js] | ||
------------------------------------------ | ||
"query": "{\"match_{{template}}\": {}}\"", | ||
"params" : { | ||
"template" : "all" | ||
------------------------------------------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters