18
18
import static org .elasticsearch .client .Requests .*;
19
19
import static org .springframework .util .StringUtils .*;
20
20
21
+ import reactor .core .publisher .Flux ;
22
+ import reactor .core .publisher .Mono ;
23
+
21
24
import java .util .Map ;
22
25
import java .util .Set ;
23
26
52
55
import org .springframework .data .elasticsearch .core .index .TemplateData ;
53
56
import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentEntity ;
54
57
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
55
- import org .springframework .data .elasticsearch .core .mapping .IndexInformation ;
56
- import org .springframework .http .HttpHeaders ;
57
58
import org .springframework .lang .Nullable ;
58
59
import org .springframework .util .Assert ;
59
60
60
- import reactor .core .publisher .Flux ;
61
- import reactor .core .publisher .Mono ;
62
-
63
61
/**
64
62
* @author Peter-Josef Meisch
65
63
* @author George Popides
@@ -74,7 +72,6 @@ class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
74
72
private final RequestFactory requestFactory ;
75
73
private final ReactiveElasticsearchOperations operations ;
76
74
private final ElasticsearchConverter converter ;
77
- private final ResponseConverter responseConverter ;
78
75
79
76
public DefaultReactiveIndexOperations (ReactiveElasticsearchOperations operations , IndexCoordinates index ) {
80
77
@@ -84,7 +81,6 @@ public DefaultReactiveIndexOperations(ReactiveElasticsearchOperations operations
84
81
this .operations = operations ;
85
82
this .converter = operations .getElasticsearchConverter ();
86
83
this .requestFactory = new RequestFactory (operations .getElasticsearchConverter ());
87
- this .responseConverter = new ResponseConverter ();
88
84
this .boundClass = null ;
89
85
this .boundIndex = index ;
90
86
}
@@ -97,7 +93,6 @@ public DefaultReactiveIndexOperations(ReactiveElasticsearchOperations operations
97
93
this .operations = operations ;
98
94
this .converter = operations .getElasticsearchConverter ();
99
95
this .requestFactory = new RequestFactory (operations .getElasticsearchConverter ());
100
- this .responseConverter = new ResponseConverter ();
101
96
this .boundClass = clazz ;
102
97
this .boundIndex = getIndexCoordinatesFor (clazz );
103
98
}
@@ -223,7 +218,7 @@ public Mono<Document> getSettings(boolean includeDefaults) {
223
218
GetSettingsRequest request = requestFactory .getSettingsRequest (indexName , includeDefaults );
224
219
225
220
return Mono .from (operations .executeWithIndicesClient (client -> client .getSettings (request )))
226
- .map (getSettingsResponse -> requestFactory .fromSettingsResponse (getSettingsResponse , indexName ));
221
+ .map (getSettingsResponse -> ResponseConverter .fromSettingsResponse (getSettingsResponse , indexName ));
227
222
}
228
223
229
224
// endregion
@@ -250,7 +245,7 @@ private Mono<Map<String, Set<AliasData>>> getAliases(@Nullable String[] aliasNam
250
245
251
246
GetAliasesRequest getAliasesRequest = requestFactory .getAliasesRequest (aliasNames , indexNames );
252
247
return Mono .from (operations .executeWithIndicesClient (client -> client .getAliases (getAliasesRequest )))
253
- .map (GetAliasesResponse ::getAliases ).map (responseConverter :: convertAliasesResponse );
248
+ .map (GetAliasesResponse ::getAliases ).map (ResponseConverter :: aliasDatas );
254
249
}
255
250
// endregion
256
251
@@ -273,7 +268,8 @@ public Mono<TemplateData> getTemplate(GetTemplateRequest getTemplateRequest) {
273
268
return Mono .from (operations .executeWithIndicesClient (client -> client .getTemplate (getIndexTemplatesRequest )))
274
269
.flatMap (response -> {
275
270
if (response != null ) {
276
- TemplateData templateData = requestFactory .getTemplateData (response , getTemplateRequest .getTemplateName ());
271
+ TemplateData templateData = ResponseConverter .getTemplateData (response ,
272
+ getTemplateRequest .getTemplateName ());
277
273
if (templateData != null ) {
278
274
return Mono .just (templateData );
279
275
}
@@ -311,12 +307,15 @@ public IndexCoordinates getIndexCoordinates() {
311
307
}
312
308
313
309
@ Override
314
- public Flux <IndexInformation > getInformation () {
315
- org .elasticsearch .client .indices .GetIndexRequest getIndexRequest = requestFactory .getIndexRequest (getIndexCoordinates ());
310
+ public Flux <IndexInformation > getInformation (IndexCoordinates index ) {
311
+
312
+ Assert .notNull (index , "index must not be null" );
316
313
317
- return Mono .from (operations .executeWithIndicesClient (client ->
318
- client .getIndex (HttpHeaders .EMPTY , getIndexRequest ).map (responseConverter ::indexInformationCollection )))
319
- .flatMapMany (Flux ::fromIterable );
314
+ org .elasticsearch .client .indices .GetIndexRequest getIndexRequest = requestFactory .getIndexRequest (index );
315
+ return Mono
316
+ .from (operations .executeWithIndicesClient (
317
+ client -> client .getIndex (getIndexRequest ).map (ResponseConverter ::getIndexInformations )))
318
+ .flatMapMany (Flux ::fromIterable );
320
319
}
321
320
322
321
private IndexCoordinates getIndexCoordinatesFor (Class <?> clazz ) {
0 commit comments