37
37
import org .springframework .data .elasticsearch .core .ResourceUtil ;
38
38
import org .springframework .data .elasticsearch .core .convert .ElasticsearchConverter ;
39
39
import org .springframework .data .elasticsearch .core .document .Document ;
40
- import org .springframework .data .elasticsearch .core .index .AliasActions ;
41
- import org .springframework .data .elasticsearch .core .index .AliasData ;
40
+ import org .springframework .data .elasticsearch .core .index .* ;
41
+ import org .springframework .data .elasticsearch .core .index .DeleteIndexTemplateRequest ;
42
42
import org .springframework .data .elasticsearch .core .index .DeleteTemplateRequest ;
43
+ import org .springframework .data .elasticsearch .core .index .ExistsIndexTemplateRequest ;
43
44
import org .springframework .data .elasticsearch .core .index .ExistsTemplateRequest ;
45
+ import org .springframework .data .elasticsearch .core .index .GetIndexTemplateRequest ;
44
46
import org .springframework .data .elasticsearch .core .index .GetTemplateRequest ;
45
- import org .springframework .data .elasticsearch .core .index .MappingBuilder ;
47
+ import org .springframework .data .elasticsearch .core .index .PutIndexTemplateRequest ;
46
48
import org .springframework .data .elasticsearch .core .index .PutTemplateRequest ;
47
- import org .springframework .data .elasticsearch .core .index .Settings ;
48
- import org .springframework .data .elasticsearch .core .index .TemplateData ;
49
49
import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentEntity ;
50
50
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
51
51
import org .springframework .lang .Nullable ;
@@ -62,30 +62,37 @@ public class IndicesTemplate extends ChildTemplate<ElasticsearchTransport, Elast
62
62
63
63
private static final Logger LOGGER = LoggerFactory .getLogger (IndicesTemplate .class );
64
64
65
+ // we need a cluster client as well because ES has put some methods from the indices API into the cluster client
66
+ // (component templates)
67
+ private final ClusterTemplate clusterTemplate ;
65
68
protected final ElasticsearchConverter elasticsearchConverter ;
66
69
@ Nullable protected final Class <?> boundClass ;
67
70
@ Nullable protected final IndexCoordinates boundIndex ;
68
71
69
- public IndicesTemplate (ElasticsearchIndicesClient client , ElasticsearchConverter elasticsearchConverter ,
70
- Class <?> boundClass ) {
72
+ public IndicesTemplate (ElasticsearchIndicesClient client , ClusterTemplate clusterTemplate ,
73
+ ElasticsearchConverter elasticsearchConverter , Class <?> boundClass ) {
71
74
super (client , elasticsearchConverter );
72
75
76
+ Assert .notNull (clusterTemplate , "cluster must not be null" );
73
77
Assert .notNull (elasticsearchConverter , "elasticsearchConverter must not be null" );
74
78
Assert .notNull (boundClass , "boundClass may not be null" );
75
79
80
+ this .clusterTemplate = clusterTemplate ;
76
81
this .elasticsearchConverter = elasticsearchConverter ;
77
82
this .boundClass = boundClass ;
78
83
this .boundIndex = null ;
79
84
80
85
}
81
86
82
- public IndicesTemplate (ElasticsearchIndicesClient client , ElasticsearchConverter elasticsearchConverter ,
83
- IndexCoordinates boundIndex ) {
87
+ public IndicesTemplate (ElasticsearchIndicesClient client , ClusterTemplate clusterTemplate ,
88
+ ElasticsearchConverter elasticsearchConverter , IndexCoordinates boundIndex ) {
84
89
super (client , elasticsearchConverter );
85
90
91
+ Assert .notNull (clusterTemplate , "cluster must not be null" );
86
92
Assert .notNull (elasticsearchConverter , "elasticsearchConverter must not be null" );
87
93
Assert .notNull (boundIndex , "boundIndex must not be null" );
88
94
95
+ this .clusterTemplate = clusterTemplate ;
89
96
this .elasticsearchConverter = elasticsearchConverter ;
90
97
this .boundClass = null ;
91
98
this .boundIndex = boundIndex ;
@@ -338,6 +345,87 @@ public boolean deleteTemplate(DeleteTemplateRequest deleteTemplateRequest) {
338
345
return execute (client -> client .deleteTemplate (deleteTemplateRequestES )).acknowledged ();
339
346
}
340
347
348
+ @ Override
349
+ public boolean putIndexTemplate (PutIndexTemplateRequest putIndexTemplateRequest ) {
350
+
351
+ co .elastic .clients .elasticsearch .indices .PutIndexTemplateRequest putIndexTemplateRequestES = requestConverter
352
+ .indicesPutIndexTemplateRequest (putIndexTemplateRequest );
353
+
354
+ return execute (client -> client .putIndexTemplate (putIndexTemplateRequestES )).acknowledged ();
355
+ }
356
+
357
+ @ Override
358
+ public boolean existsIndexTemplate (ExistsIndexTemplateRequest existsIndexTemplateRequest ) {
359
+
360
+ Assert .notNull (existsIndexTemplateRequest , "existsIndexTemplateRequest must not be null" );
361
+
362
+ co .elastic .clients .elasticsearch .indices .ExistsIndexTemplateRequest existsTemplateRequestES = requestConverter
363
+ .indicesExistsIndexTemplateRequest (existsIndexTemplateRequest );
364
+ return execute (client -> client .existsIndexTemplate (existsTemplateRequestES )).value ();
365
+ }
366
+
367
+ @ Override
368
+ public List <TemplateResponse > getIndexTemplate (GetIndexTemplateRequest getIndexTemplateRequest ) {
369
+
370
+ Assert .notNull (getIndexTemplateRequest , "getIndexTemplateRequest must not be null" );
371
+
372
+ co .elastic .clients .elasticsearch .indices .GetIndexTemplateRequest getIndexTemplateRequestES = requestConverter
373
+ .indicesGetIndexTemplateRequest (getIndexTemplateRequest );
374
+ var getIndexTemplateResponse = execute (client -> client .getIndexTemplate (getIndexTemplateRequestES ));
375
+ return responseConverter .getIndexTemplates (getIndexTemplateResponse );
376
+ }
377
+
378
+ @ Override
379
+ public boolean deleteIndexTemplate (DeleteIndexTemplateRequest deleteIndexTemplateRequest ) {
380
+
381
+ Assert .notNull (deleteIndexTemplateRequest , "deleteIndexTemplateRequest must not be null" );
382
+
383
+ co .elastic .clients .elasticsearch .indices .DeleteIndexTemplateRequest deleteIndexTemplateRequestES = requestConverter
384
+ .indicesDeleteIndexTemplateRequest (deleteIndexTemplateRequest );
385
+ return execute (client -> client .deleteIndexTemplate (deleteIndexTemplateRequestES )).acknowledged ();
386
+ }
387
+
388
+ @ Override
389
+ public boolean putComponentTemplate (PutComponentTemplateRequest putComponentTemplateRequest ) {
390
+
391
+ Assert .notNull (putComponentTemplateRequest , "putComponentTemplateRequest must not be null" );
392
+
393
+ co .elastic .clients .elasticsearch .cluster .PutComponentTemplateRequest putComponentTemplateRequestES = requestConverter
394
+ .clusterPutComponentTemplateRequest (putComponentTemplateRequest );
395
+ // the new Elasticsearch client has this call in the cluster index
396
+ return clusterTemplate .execute (client -> client .putComponentTemplate (putComponentTemplateRequestES )).acknowledged ();
397
+ }
398
+
399
+ @ Override
400
+ public boolean existsComponentTemplate (ExistsComponentTemplateRequest existsComponentTemplateRequest ) {
401
+
402
+ Assert .notNull (existsComponentTemplateRequest , "existsComponentTemplateRequest must not be null" );
403
+
404
+ co .elastic .clients .elasticsearch .cluster .ExistsComponentTemplateRequest existsComponentTemplateRequestES = requestConverter
405
+ .clusterExistsComponentTemplateRequest (existsComponentTemplateRequest );
406
+ return clusterTemplate .execute (client -> client .existsComponentTemplate (existsComponentTemplateRequestES )).value ();
407
+ }
408
+
409
+ @ Override
410
+ public List <TemplateResponse > getComponentTemplate (GetComponentTemplateRequest getComponentTemplateRequest ) {
411
+
412
+ co .elastic .clients .elasticsearch .cluster .GetComponentTemplateRequest getComponentTemplateRequestES = requestConverter
413
+ .clusterGetComponentTemplateRequest (getComponentTemplateRequest );
414
+ var response = clusterTemplate .execute (client -> client .getComponentTemplate (getComponentTemplateRequestES ));
415
+ return responseConverter .clusterGetComponentTemplates (response );
416
+ }
417
+
418
+ @ Override
419
+ public boolean deleteComponentTemplate (DeleteComponentTemplateRequest deleteComponentTemplateRequest ) {
420
+
421
+ Assert .notNull (deleteComponentTemplateRequest , "deleteComponentTemplateRequest must not be null" );
422
+
423
+ co .elastic .clients .elasticsearch .cluster .DeleteComponentTemplateRequest deleteComponentTemplateRequestES = requestConverter
424
+ .clusterDeleteComponentTemplateRequest (deleteComponentTemplateRequest );
425
+ return clusterTemplate .execute (client -> client .deleteComponentTemplate (deleteComponentTemplateRequestES ))
426
+ .acknowledged ();
427
+ }
428
+
341
429
@ Override
342
430
public List <IndexInformation > getInformation (IndexCoordinates indexCoordinates ) {
343
431
0 commit comments