Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/96197.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 96197
summary: "[Search Applications] Support arrays in stored mustache templates"
area: Application
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ setup:
field_value:
type: string

- do:
search_application.put:
name: another-test-search-application
body:
indices: [ "test-search-index1", "test-search-index2" ]
template:
script:
source: "{ \"query\": { \"multi_match\":{ \"query\": \"{{query_string}}\", \"fields\": [{{#text_fields}}\"{{name}}^{{boost}}\",{{/text_fields}}] } } }"
params:
query_string: "elastic"
text_fields:
- name: field1
boost: 1
- name: field2
boost: 2
- name: field3
boost: 3
lang: "mustache"

- do:
index:
index: test-search-index1
Expand Down Expand Up @@ -145,6 +164,32 @@ teardown:
- match: { hits.total.value: 1 }
- match: { hits.hits.0._id: "doc2" }

---
"Query Search Application with list of parameters":
- skip:
features: headers
version: all
reason: "AwaitsFix https://github.com/elastic/enterprise-search-team/issues/4540"

- do:
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
search_application.search:
name: test-search-application-with-list
body:
params:
query_string: elastic
text_fields:
- name: field1
boost: 1
- name: field2
boost: 2
- name: field3
boost: 3


- match: { hits.total.value: 1 }
- match: { hits.hits.0._id: "doc2" }

---
"Query Search Application with invalid parameter validation":
- skip:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public SearchSourceBuilder renderQuery(SearchApplication searchApplication, Map<
template.validateTemplateParams(templateParams);
final Map<String, Object> renderedTemplateParams = renderTemplate(searchApplication, templateParams);
final Script script = template.script();

TemplateScript compiledTemplate = scriptService.compile(script, TemplateScript.CONTEXT).newInstance(renderedTemplateParams);
String requestSource = compiledTemplate.execute();
final String requestSource = SearchTemplateHelper.stripTrailingComma(compiledTemplate.execute());
XContentParserConfiguration parserConfig = XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE);
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(parserConfig, requestSource)) {
Expand Down