Convert watcher search source to json

If any format other than json is sent, it should get converted to json, as watcher works under the assumption that the script is a template, hence json.

Original commit: elastic/x-pack-elasticsearch@554bcd306b
This commit is contained in:
javanna 2017-02-24 15:19:46 +01:00 committed by Luca Cavanna
parent 39ccc67a7b
commit adc9808eff
1 changed files with 2 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
@ -195,7 +196,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (BODY_FIELD.match(currentFieldName)) {
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.copyCurrentStructure(parser);
searchSource = builder.bytes();
}