44
44
import org .opensearch .common .bytes .BytesReference ;
45
45
import org .opensearch .common .settings .Settings ;
46
46
import org .opensearch .common .xcontent .DeprecationHandler ;
47
+ import org .opensearch .common .xcontent .MediaType ;
47
48
import org .opensearch .common .xcontent .NamedXContentRegistry ;
48
49
import org .opensearch .common .xcontent .ToXContentObject ;
49
50
import org .opensearch .common .xcontent .XContentBuilder ;
64
65
65
66
/**
66
67
* A request to create an index.
68
+ *
69
+ * @opensearch.api
67
70
*/
68
71
public class CreateIndexRequest extends TimedRequest implements Validatable , ToXContentObject {
69
72
static final ParseField MAPPINGS = new ParseField ("mappings" );
@@ -122,12 +125,23 @@ public CreateIndexRequest settings(Settings settings) {
122
125
123
126
/**
124
127
* The settings to create the index with (either json or yaml format)
128
+ *
129
+ * @deprecated use {@link #settings(String source, MediaType mediaType)} instead
125
130
*/
131
+ @ Deprecated
126
132
public CreateIndexRequest settings (String source , XContentType xContentType ) {
127
133
this .settings = Settings .builder ().loadFromSource (source , xContentType ).build ();
128
134
return this ;
129
135
}
130
136
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
+
131
145
/**
132
146
* Allows to set the settings using a json builder.
133
147
*/
@@ -159,11 +173,26 @@ public XContentType mappingsXContentType() {
159
173
*
160
174
* @param source The mapping source
161
175
* @param xContentType The content type of the source
176
+ *
177
+ * @deprecated use {@link #mapping(String source, MediaType mediaType)} instead
162
178
*/
179
+ @ Deprecated
163
180
public CreateIndexRequest mapping (String source , XContentType xContentType ) {
164
181
return mapping (new BytesArray (source ), xContentType );
165
182
}
166
183
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
+
167
196
/**
168
197
* Adds mapping that will be added when the index gets created.
169
198
*
@@ -199,14 +228,32 @@ public CreateIndexRequest mapping(Map<String, ?> source) {
199
228
*
200
229
* @param source The mapping source
201
230
* @param xContentType the content type of the mapping source
231
+ *
232
+ * @deprecated use {@link #mapping(BytesReference source, MediaType mediaType)} instead
202
233
*/
234
+ @ Deprecated
203
235
public CreateIndexRequest mapping (BytesReference source , XContentType xContentType ) {
204
236
Objects .requireNonNull (xContentType );
205
237
mappings = source ;
206
238
mappingsXContentType = xContentType ;
207
239
return this ;
208
240
}
209
241
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
+
210
257
public Set <Alias > aliases () {
211
258
return this .aliases ;
212
259
}
@@ -233,15 +280,35 @@ public CreateIndexRequest aliases(XContentBuilder source) {
233
280
234
281
/**
235
282
* Sets the aliases that will be associated with the index when it gets created
283
+ *
284
+ * @deprecated use {@link #aliases(String, MediaType)} instead
236
285
*/
286
+ @ Deprecated
237
287
public CreateIndexRequest aliases (String source , XContentType contentType ) {
238
288
return aliases (new BytesArray (source ), contentType );
239
289
}
240
290
241
291
/**
242
292
* Sets the aliases that will be associated with the index when it gets created
243
293
*/
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
244
304
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 ) {
245
312
// EMPTY is safe here because we never call namedObject
246
313
try (
247
314
XContentParser parser = XContentHelper .createParser (
@@ -282,11 +349,23 @@ public CreateIndexRequest aliases(Collection<Alias> aliases) {
282
349
* Sets the settings and mappings as a single source.
283
350
*
284
351
* Note that the mapping definition should *not* be nested under a type name.
352
+ *
353
+ * @deprecated use {@link #source(String, MediaType)} instead
285
354
*/
355
+ @ Deprecated
286
356
public CreateIndexRequest source (String source , XContentType xContentType ) {
287
357
return source (new BytesArray (source ), xContentType );
288
358
}
289
359
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
+
290
369
/**
291
370
* Sets the settings and mappings as a single source.
292
371
*
@@ -300,13 +379,27 @@ public CreateIndexRequest source(XContentBuilder source) {
300
379
* Sets the settings and mappings as a single source.
301
380
*
302
381
* Note that the mapping definition should *not* be nested under a type name.
382
+ *
383
+ * @deprecated use {@link #source(BytesReference, MediaType)} instead
303
384
*/
385
+ @ Deprecated
304
386
public CreateIndexRequest source (BytesReference source , XContentType xContentType ) {
305
387
Objects .requireNonNull (xContentType );
306
388
source (XContentHelper .convertToMap (source , false , xContentType ).v2 ());
307
389
return this ;
308
390
}
309
391
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
+
310
403
/**
311
404
* Sets the settings and mappings as a single source.
312
405
*
0 commit comments