55
55
56
56
import java .io .ByteArrayInputStream ;
57
57
import java .io .ByteArrayOutputStream ;
58
+ import java .io .StringReader ;
58
59
import java .nio .charset .StandardCharsets ;
59
60
import java .time .Duration ;
60
61
import java .util .ArrayList ;
@@ -144,14 +145,12 @@ public CreateIndexRequest indicesCreateRequest(IndexCoordinates indexCoordinates
144
145
createRequestBuilder .index (indexCoordinates .getIndexName ());
145
146
146
147
// 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 ()))));
150
150
151
151
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 ()))));
155
154
}
156
155
157
156
return createRequestBuilder .build ();
@@ -243,11 +242,12 @@ public PutMappingRequest indicesPutMappingRequest(IndexCoordinates indexCoordina
243
242
Assert .notNull (indexCoordinates , "indexCoordinates must not be null" );
244
243
Assert .notNull (mapping , "mapping must not be null" );
245
244
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 ();
249
249
250
- return builder . build () ;
250
+ return request ;
251
251
}
252
252
253
253
public GetMappingRequest indicesGetMappingRequest (IndexCoordinates indexCoordinates ) {
@@ -257,23 +257,6 @@ public GetMappingRequest indicesGetMappingRequest(IndexCoordinates indexCoordina
257
257
return new GetMappingRequest .Builder ().index (Arrays .asList (indexCoordinates .getIndexNames ())).build ();
258
258
}
259
259
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
-
277
260
private Property getProperty (Object value ) {
278
261
// noinspection SpellCheckingInspection
279
262
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
0 commit comments