From 594f00c5828c8ea9875ae672afe3da41af27509c Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 22 Feb 2017 14:48:53 +0100 Subject: [PATCH] Remove content type auto-detection from search templates Now that search templates always get converted to json, we don't need to try and auto-detect their content-type, which anyways didn't work as expected before given that only json was really working. --- .../script/mustache/SearchTemplateResponse.java | 4 +++- .../script/mustache/TransportSearchTemplateAction.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateResponse.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateResponse.java index 6158e80c241..22d7da774eb 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateResponse.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateResponse.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.StatusToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -81,7 +82,8 @@ public class SearchTemplateResponse extends ActionResponse implements StatusToX response.toXContent(builder, params); } else { builder.startObject(); - builder.rawField("template_output", source); + //we can assume the template is always json as we convert it before compiling it + builder.rawField("template_output", source, XContentType.JSON); builder.endObject(); } return builder; diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java index 7d83fcaf581..d7b04062382 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; @@ -82,8 +83,8 @@ public class TransportSearchTemplateAction extends HandledTransportAction