diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java index 512f0e77f9..3d413e1367 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java @@ -33,6 +33,7 @@ package org.opensearch.client.opensearch.indices; import jakarta.json.stream.JsonGenerator; +import java.io.StringReader; import java.util.HashMap; import java.util.Map; import java.util.function.Function; @@ -43,6 +44,7 @@ import org.opensearch.client.json.JsonpSerializable; import org.opensearch.client.json.ObjectBuilderDeserializer; import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.opensearch._types.Time; @@ -304,6 +306,25 @@ public final Builder mappings(@Nullable TypeMapping value) { return this; } + /** + * Mapping for fields in the index. If specified, this mapping can include: + * + *

+ * API name: {@code mappings} + */ + public final Builder mappings(@Nullable String typeMappingJson) { + return this.mappings(deserialize(TypeMapping._DESERIALIZER, typeMappingJson)); + } + + private T deserialize(JsonpDeserializer deserializer, String json) { + JsonpMapper jsonpMapper = new JacksonJsonpMapper(); + return deserializer.deserialize(jsonpMapper.jsonProvider().createParser(new StringReader(json)), jsonpMapper); + } + /** * Mapping for fields in the index. If specified, this mapping can include: *