78
78
79
79
import java .io .ByteArrayInputStream ;
80
80
import java .io .ByteArrayOutputStream ;
81
+ import java .io .StringReader ;
81
82
import java .nio .charset .StandardCharsets ;
82
83
import java .time .Duration ;
83
84
import java .util .ArrayList ;
@@ -176,14 +177,12 @@ public CreateIndexRequest indicesCreateRequest(IndexCoordinates indexCoordinates
176
177
createRequestBuilder .index (indexCoordinates .getIndexName ());
177
178
178
179
// note: the new client does not support the index.storeType anymore
179
- String settingsJson = Document .from (settings ).toJson ();
180
- IndexSettings indexSettings = fromJson (settingsJson , IndexSettings ._DESERIALIZER );
181
- createRequestBuilder .settings (indexSettings );
180
+ createRequestBuilder .settings (IndexSettings .of (b -> b //
181
+ .withJson (new StringReader (Document .from (settings ).toJson ()))));
182
182
183
183
if (mapping != null ) {
184
- String mappingJson = mapping .toJson ();
185
- TypeMapping typeMapping = fromJson (mappingJson , TypeMapping ._DESERIALIZER );
186
- createRequestBuilder .mappings (typeMapping );
184
+ createRequestBuilder .mappings (TypeMapping .of (b -> b //
185
+ .withJson (new StringReader (mapping .toJson ()))));
187
186
}
188
187
189
188
return createRequestBuilder .build ();
@@ -275,11 +274,12 @@ public PutMappingRequest indicesPutMappingRequest(IndexCoordinates indexCoordina
275
274
Assert .notNull (indexCoordinates , "indexCoordinates must not be null" );
276
275
Assert .notNull (mapping , "mapping must not be null" );
277
276
278
- PutMappingRequest .Builder builder = new PutMappingRequest .Builder ();
279
- builder .index (Arrays .asList (indexCoordinates .getIndexNames ()));
280
- addPropertiesToMapping (builder , mapping );
277
+ PutMappingRequest request = new PutMappingRequest .Builder () //
278
+ .withJson (new StringReader (mapping .toJson ())) //
279
+ .index (Arrays .asList (indexCoordinates .getIndexNames ())) //
280
+ .build ();
281
281
282
- return builder . build () ;
282
+ return request ;
283
283
}
284
284
285
285
public GetMappingRequest indicesGetMappingRequest (IndexCoordinates indexCoordinates ) {
@@ -289,23 +289,6 @@ public GetMappingRequest indicesGetMappingRequest(IndexCoordinates indexCoordina
289
289
return new GetMappingRequest .Builder ().index (Arrays .asList (indexCoordinates .getIndexNames ())).build ();
290
290
}
291
291
292
- private void addPropertiesToMapping (PutMappingRequest .Builder builder , Document mapping ) {
293
- Object properties = mapping .get ("properties" );
294
-
295
- if (properties != null ) {
296
-
297
- if (properties instanceof Map ) {
298
- Map <String , Property > propertiesMap = new HashMap <>();
299
- // noinspection unchecked
300
- ((Map <String , Object >) properties ).forEach ((key , value ) -> {
301
- Property property = getProperty (value );
302
- propertiesMap .put (key , property );
303
- });
304
- builder .properties (propertiesMap );
305
- }
306
- }
307
- }
308
-
309
292
private Property getProperty (Object value ) {
310
293
// noinspection SpellCheckingInspection
311
294
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
0 commit comments