5555
5656import java .io .ByteArrayInputStream ;
5757import java .io .ByteArrayOutputStream ;
58+ import java .io .StringReader ;
5859import java .nio .charset .StandardCharsets ;
5960import java .time .Duration ;
6061import java .util .ArrayList ;
@@ -144,14 +145,12 @@ public CreateIndexRequest indicesCreateRequest(IndexCoordinates indexCoordinates
144145 createRequestBuilder .index (indexCoordinates .getIndexName ());
145146
146147 // note: the new client does not support the index.storeType anymore
147- String settingsJson = Document .from (settings ).toJson ();
148- IndexSettings indexSettings = fromJson (settingsJson , IndexSettings ._DESERIALIZER );
149- createRequestBuilder .settings (indexSettings );
148+ createRequestBuilder .settings (IndexSettings .of (b -> b //
149+ .withJson (new StringReader (Document .from (settings ).toJson ()))));
150150
151151 if (mapping != null ) {
152- String mappingJson = mapping .toJson ();
153- TypeMapping typeMapping = fromJson (mappingJson , TypeMapping ._DESERIALIZER );
154- createRequestBuilder .mappings (typeMapping );
152+ createRequestBuilder .mappings (TypeMapping .of (b -> b //
153+ .withJson (new StringReader (mapping .toJson ()))));
155154 }
156155
157156 return createRequestBuilder .build ();
@@ -243,11 +242,12 @@ public PutMappingRequest indicesPutMappingRequest(IndexCoordinates indexCoordina
243242 Assert .notNull (indexCoordinates , "indexCoordinates must not be null" );
244243 Assert .notNull (mapping , "mapping must not be null" );
245244
246- PutMappingRequest .Builder builder = new PutMappingRequest .Builder ();
247- builder .index (Arrays .asList (indexCoordinates .getIndexNames ()));
248- addPropertiesToMapping (builder , mapping );
245+ PutMappingRequest request = new PutMappingRequest .Builder () //
246+ .withJson (new StringReader (mapping .toJson ())) //
247+ .index (Arrays .asList (indexCoordinates .getIndexNames ())) //
248+ .build ();
249249
250- return builder . build () ;
250+ return request ;
251251 }
252252
253253 public GetMappingRequest indicesGetMappingRequest (IndexCoordinates indexCoordinates ) {
@@ -257,23 +257,6 @@ public GetMappingRequest indicesGetMappingRequest(IndexCoordinates indexCoordina
257257 return new GetMappingRequest .Builder ().index (Arrays .asList (indexCoordinates .getIndexNames ())).build ();
258258 }
259259
260- private void addPropertiesToMapping (PutMappingRequest .Builder builder , Document mapping ) {
261- Object properties = mapping .get ("properties" );
262-
263- if (properties != null ) {
264-
265- if (properties instanceof Map ) {
266- Map <String , Property > propertiesMap = new HashMap <>();
267- // noinspection unchecked
268- ((Map <String , Object >) properties ).forEach ((key , value ) -> {
269- Property property = getProperty (value );
270- propertiesMap .put (key , property );
271- });
272- builder .properties (propertiesMap );
273- }
274- }
275- }
276-
277260 private Property getProperty (Object value ) {
278261 // noinspection SpellCheckingInspection
279262 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
0 commit comments