diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java index 87fbe99c17e45..5f22691b046eb 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java @@ -70,7 +70,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest aliases = new HashSet<>(); @@ -252,7 +252,8 @@ private PutIndexTemplateRequest internalMapping(Map source) { builder.map(source); Objects.requireNonNull(builder.contentType()); try { - mappings = XContentHelper.convertToJson(BytesReference.bytes(builder), false, false, builder.contentType()); + mappings = new BytesArray( + XContentHelper.convertToJson(BytesReference.bytes(builder), false, false, builder.contentType())); return this; } catch (IOException e) { throw new UncheckedIOException("failed to convert source to json", e); @@ -262,7 +263,7 @@ private PutIndexTemplateRequest internalMapping(Map source) { } } - public String mappings() { + public BytesReference mappings() { return this.mappings; } @@ -436,7 +437,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (mappings != null) { builder.field("mappings"); try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappings)) { + DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappings.utf8ToString())) { builder.copyCurrentStructure(parser); } }