4444import org .opensearch .common .bytes .BytesReference ;
4545import org .opensearch .common .settings .Settings ;
4646import org .opensearch .common .xcontent .DeprecationHandler ;
47+ import org .opensearch .common .xcontent .MediaType ;
4748import org .opensearch .common .xcontent .NamedXContentRegistry ;
4849import org .opensearch .common .xcontent .ToXContentObject ;
4950import org .opensearch .common .xcontent .XContentBuilder ;
6465
6566/**
6667 * A request to create an index.
68+ *
69+ * @opensearch.api
6770 */
6871public class CreateIndexRequest extends TimedRequest implements Validatable , ToXContentObject {
6972 static final ParseField MAPPINGS = new ParseField ("mappings" );
@@ -122,12 +125,23 @@ public CreateIndexRequest settings(Settings settings) {
122125
123126 /**
124127 * The settings to create the index with (either json or yaml format)
128+ *
129+ * @deprecated use {@link #settings(String source, MediaType mediaType)} instead
125130 */
131+ @ Deprecated
126132 public CreateIndexRequest settings (String source , XContentType xContentType ) {
127133 this .settings = Settings .builder ().loadFromSource (source , xContentType ).build ();
128134 return this ;
129135 }
130136
137+ /**
138+ * The settings to create the index with (either json or yaml format)
139+ */
140+ public CreateIndexRequest settings (String source , MediaType mediaType ) {
141+ this .settings = Settings .builder ().loadFromSource (source , mediaType ).build ();
142+ return this ;
143+ }
144+
131145 /**
132146 * Allows to set the settings using a json builder.
133147 */
@@ -159,11 +173,26 @@ public XContentType mappingsXContentType() {
159173 *
160174 * @param source The mapping source
161175 * @param xContentType The content type of the source
176+ *
177+ * @deprecated use {@link #mapping(String source, MediaType mediaType)} instead
162178 */
179+ @ Deprecated
163180 public CreateIndexRequest mapping (String source , XContentType xContentType ) {
164181 return mapping (new BytesArray (source ), xContentType );
165182 }
166183
184+ /**
185+ * Adds mapping that will be added when the index gets created.
186+ *
187+ * Note that the definition should *not* be nested under a type name.
188+ *
189+ * @param source The mapping source
190+ * @param mediaType The media type of the source
191+ */
192+ public CreateIndexRequest mapping (String source , MediaType mediaType ) {
193+ return mapping (new BytesArray (source ), mediaType );
194+ }
195+
167196 /**
168197 * Adds mapping that will be added when the index gets created.
169198 *
@@ -199,14 +228,32 @@ public CreateIndexRequest mapping(Map<String, ?> source) {
199228 *
200229 * @param source The mapping source
201230 * @param xContentType the content type of the mapping source
231+ *
232+ * @deprecated use {@link #mapping(BytesReference source, MediaType mediaType)} instead
202233 */
234+ @ Deprecated
203235 public CreateIndexRequest mapping (BytesReference source , XContentType xContentType ) {
204236 Objects .requireNonNull (xContentType );
205237 mappings = source ;
206238 mappingsXContentType = xContentType ;
207239 return this ;
208240 }
209241
242+ /**
243+ * Adds mapping that will be added when the index gets created.
244+ *
245+ * Note that the definition should *not* be nested under a type name.
246+ *
247+ * @param source The mapping source
248+ * @param mediaType the content type of the mapping source
249+ */
250+ public CreateIndexRequest mapping (BytesReference source , MediaType mediaType ) {
251+ Objects .requireNonNull (mediaType );
252+ mappings = source ;
253+ mappingsXContentType = (XContentType ) mediaType ;
254+ return this ;
255+ }
256+
210257 public Set <Alias > aliases () {
211258 return this .aliases ;
212259 }
@@ -233,15 +280,35 @@ public CreateIndexRequest aliases(XContentBuilder source) {
233280
234281 /**
235282 * Sets the aliases that will be associated with the index when it gets created
283+ *
284+ * @deprecated use {@link #aliases(String, MediaType)} instead
236285 */
286+ @ Deprecated
237287 public CreateIndexRequest aliases (String source , XContentType contentType ) {
238288 return aliases (new BytesArray (source ), contentType );
239289 }
240290
241291 /**
242292 * Sets the aliases that will be associated with the index when it gets created
243293 */
294+ public CreateIndexRequest aliases (String source , MediaType mediaType ) {
295+ return aliases (new BytesArray (source ), mediaType );
296+ }
297+
298+ /**
299+ * Sets the aliases that will be associated with the index when it gets created
300+ *
301+ * @deprecated use {@link #aliases(BytesReference source, MediaType contentType)} instead
302+ */
303+ @ Deprecated
244304 public CreateIndexRequest aliases (BytesReference source , XContentType contentType ) {
305+ return aliases (source , (MediaType ) contentType );
306+ }
307+
308+ /**
309+ * Sets the aliases that will be associated with the index when it gets created
310+ */
311+ public CreateIndexRequest aliases (BytesReference source , MediaType contentType ) {
245312 // EMPTY is safe here because we never call namedObject
246313 try (
247314 XContentParser parser = XContentHelper .createParser (
@@ -282,11 +349,23 @@ public CreateIndexRequest aliases(Collection<Alias> aliases) {
282349 * Sets the settings and mappings as a single source.
283350 *
284351 * Note that the mapping definition should *not* be nested under a type name.
352+ *
353+ * @deprecated use {@link #source(String, MediaType)} instead
285354 */
355+ @ Deprecated
286356 public CreateIndexRequest source (String source , XContentType xContentType ) {
287357 return source (new BytesArray (source ), xContentType );
288358 }
289359
360+ /**
361+ * Sets the settings and mappings as a single source.
362+ *
363+ * Note that the mapping definition should *not* be nested under a type name.
364+ */
365+ public CreateIndexRequest source (String source , MediaType mediaType ) {
366+ return source (new BytesArray (source ), mediaType );
367+ }
368+
290369 /**
291370 * Sets the settings and mappings as a single source.
292371 *
@@ -300,13 +379,27 @@ public CreateIndexRequest source(XContentBuilder source) {
300379 * Sets the settings and mappings as a single source.
301380 *
302381 * Note that the mapping definition should *not* be nested under a type name.
382+ *
383+ * @deprecated use {@link #source(BytesReference, MediaType)} instead
303384 */
385+ @ Deprecated
304386 public CreateIndexRequest source (BytesReference source , XContentType xContentType ) {
305387 Objects .requireNonNull (xContentType );
306388 source (XContentHelper .convertToMap (source , false , xContentType ).v2 ());
307389 return this ;
308390 }
309391
392+ /**
393+ * Sets the settings and mappings as a single source.
394+ *
395+ * Note that the mapping definition should *not* be nested under a type name.
396+ */
397+ public CreateIndexRequest source (BytesReference source , MediaType mediaType ) {
398+ Objects .requireNonNull (mediaType );
399+ source (XContentHelper .convertToMap (source , false , mediaType ).v2 ());
400+ return this ;
401+ }
402+
310403 /**
311404 * Sets the settings and mappings as a single source.
312405 *
0 commit comments