18
18
import static org .elasticsearch .client .Requests .*;
19
19
import static org .springframework .util .StringUtils .*;
20
20
21
- import reactor .core .publisher .Mono ;
22
-
23
21
import java .util .Map ;
24
22
import java .util .Set ;
25
23
38
36
import org .slf4j .Logger ;
39
37
import org .slf4j .LoggerFactory ;
40
38
import org .springframework .core .annotation .AnnotatedElementUtils ;
41
- import org .springframework .core .annotation .AnnotationAttributes ;
42
39
import org .springframework .dao .InvalidDataAccessApiUsageException ;
43
40
import org .springframework .data .elasticsearch .NoSuchIndexException ;
44
41
import org .springframework .data .elasticsearch .annotations .Mapping ;
55
52
import org .springframework .data .elasticsearch .core .index .TemplateData ;
56
53
import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentEntity ;
57
54
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
55
+ import org .springframework .data .elasticsearch .core .mapping .IndexInformation ;
56
+ import org .springframework .http .HttpHeaders ;
58
57
import org .springframework .lang .Nullable ;
59
58
import org .springframework .util .Assert ;
60
59
60
+ import reactor .core .publisher .Flux ;
61
+ import reactor .core .publisher .Mono ;
62
+
61
63
/**
62
64
* @author Peter-Josef Meisch
65
+ * @author George Popides
63
66
* @since 4.1
64
67
*/
65
68
class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
@@ -71,6 +74,7 @@ class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
71
74
private final RequestFactory requestFactory ;
72
75
private final ReactiveElasticsearchOperations operations ;
73
76
private final ElasticsearchConverter converter ;
77
+ private final ResponseConverter responseConverter ;
74
78
75
79
public DefaultReactiveIndexOperations (ReactiveElasticsearchOperations operations , IndexCoordinates index ) {
76
80
@@ -80,6 +84,7 @@ public DefaultReactiveIndexOperations(ReactiveElasticsearchOperations operations
80
84
this .operations = operations ;
81
85
this .converter = operations .getElasticsearchConverter ();
82
86
this .requestFactory = new RequestFactory (operations .getElasticsearchConverter ());
87
+ this .responseConverter = new ResponseConverter ();
83
88
this .boundClass = null ;
84
89
this .boundIndex = index ;
85
90
}
@@ -92,6 +97,7 @@ public DefaultReactiveIndexOperations(ReactiveElasticsearchOperations operations
92
97
this .operations = operations ;
93
98
this .converter = operations .getElasticsearchConverter ();
94
99
this .requestFactory = new RequestFactory (operations .getElasticsearchConverter ());
100
+ this .responseConverter = new ResponseConverter ();
95
101
this .boundClass = clazz ;
96
102
this .boundIndex = getIndexCoordinatesFor (clazz );
97
103
}
@@ -159,11 +165,11 @@ public Mono<Document> createMapping() {
159
165
@ Override
160
166
public Mono <Document > createMapping (Class <?> clazz ) {
161
167
162
- Mapping mappingAnnotation = AnnotatedElementUtils .findMergedAnnotation (clazz , Mapping .class );
168
+ Mapping mappingAnnotation = AnnotatedElementUtils .findMergedAnnotation (clazz , Mapping .class );
163
169
164
- if (mappingAnnotation != null ) {
165
- return loadDocument (mappingAnnotation .mappingPath (), "@Mapping" );
166
- }
170
+ if (mappingAnnotation != null ) {
171
+ return loadDocument (mappingAnnotation .mappingPath (), "@Mapping" );
172
+ }
167
173
168
174
String mapping = new MappingBuilder (converter ).buildPropertyMapping (clazz );
169
175
return Mono .just (Document .parse (mapping ));
@@ -201,11 +207,11 @@ public Mono<Document> createSettings() {
201
207
@ Override
202
208
public Mono <Document > createSettings (Class <?> clazz ) {
203
209
204
- Setting setting = AnnotatedElementUtils .findMergedAnnotation (clazz , Setting .class );
210
+ Setting setting = AnnotatedElementUtils .findMergedAnnotation (clazz , Setting .class );
205
211
206
- if (setting != null ) {
207
- return loadDocument (setting .settingPath (), "@Setting" );
208
- }
212
+ if (setting != null ) {
213
+ return loadDocument (setting .settingPath (), "@Setting" );
214
+ }
209
215
210
216
return Mono .just (getRequiredPersistentEntity (clazz ).getDefaultSettings ());
211
217
}
@@ -244,7 +250,7 @@ private Mono<Map<String, Set<AliasData>>> getAliases(@Nullable String[] aliasNam
244
250
245
251
GetAliasesRequest getAliasesRequest = requestFactory .getAliasesRequest (aliasNames , indexNames );
246
252
return Mono .from (operations .executeWithIndicesClient (client -> client .getAliases (getAliasesRequest )))
247
- .map (GetAliasesResponse ::getAliases ).map (requestFactory ::convertAliasesResponse );
253
+ .map (GetAliasesResponse ::getAliases ).map (responseConverter ::convertAliasesResponse );
248
254
}
249
255
// endregion
250
256
@@ -304,6 +310,15 @@ public IndexCoordinates getIndexCoordinates() {
304
310
return (boundClass != null ) ? getIndexCoordinatesFor (boundClass ) : boundIndex ;
305
311
}
306
312
313
+ @ Override
314
+ public Flux <IndexInformation > getInformation () {
315
+ org .elasticsearch .client .indices .GetIndexRequest getIndexRequest = requestFactory .getIndexRequest (getIndexCoordinates ());
316
+
317
+ return Mono .from (operations .executeWithIndicesClient (client ->
318
+ client .getIndex (HttpHeaders .EMPTY , getIndexRequest ).map (responseConverter ::indexInformationCollection )))
319
+ .flatMapMany (Flux ::fromIterable );
320
+ }
321
+
307
322
private IndexCoordinates getIndexCoordinatesFor (Class <?> clazz ) {
308
323
return operations .getElasticsearchConverter ().getMappingContext ().getRequiredPersistentEntity (clazz )
309
324
.getIndexCoordinates ();
0 commit comments