mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Adds support for storing mustache based query templates that can later be filled with query parameter values at execution time. Templates may be both quoted, non-quoted and referencing templates stored in config/scripts/*.mustache by file name. See docs/reference/query-dsl/queries/template-query.asciidoc for templating examples. Implementation detail: mustache itself is being shaded as it depends directly on guava - so having it marked optional but included in the final distribution raises chances of version conflicts downstream. Fixes #4879
42 lines
1.0 KiB
YAML
42 lines
1.0 KiB
YAML
---
|
|
"Template query":
|
|
|
|
- do:
|
|
index:
|
|
index: test
|
|
type: testtype
|
|
id: 1
|
|
body: { "text": "value1" }
|
|
- do:
|
|
index:
|
|
index: test
|
|
type: testtype
|
|
id: 2
|
|
body: { "text": "value2" }
|
|
- do:
|
|
indices.refresh: {}
|
|
|
|
- do:
|
|
search:
|
|
body: { "query": { "template": { "query": { "term": { "text": { "value": "{{template}}" } } }, "params": { "template": "value1" } } } }
|
|
|
|
- match: { hits.total: 1 }
|
|
|
|
- do:
|
|
search:
|
|
body: { "query": { "template": { "query": {"match_{{template}}": {}}, "params" : { "template" : "all" } } } }
|
|
|
|
- match: { hits.total: 2 }
|
|
|
|
- do:
|
|
search:
|
|
body: { "query": { "template": { "query": "{ \"term\": { \"text\": { \"value\": \"{{template}}\" } } }", "params": { "template": "value1" } } } }
|
|
|
|
- match: { hits.total: 1 }
|
|
|
|
- do:
|
|
search:
|
|
body: { "query": { "template": { "query": "{\"match_{{template}}\": {}}", "params" : { "template" : "all" } } } }
|
|
|
|
- match: { hits.total: 2 }
|