4545import org .apache .http .util .EntityUtils ;
4646import org .elasticsearch .ElasticsearchException ;
4747import org .elasticsearch .ElasticsearchStatusException ;
48+ import org .elasticsearch .action .admin .cluster .health .ClusterHealthRequest ;
49+ import org .elasticsearch .action .admin .cluster .health .ClusterHealthResponse ;
4850import org .elasticsearch .action .admin .indices .alias .IndicesAliasesRequest ;
4951import org .elasticsearch .action .admin .indices .alias .get .GetAliasesRequest ;
5052import org .elasticsearch .action .admin .indices .close .CloseIndexRequest ;
105107import org .springframework .data .elasticsearch .client .ElasticsearchHost ;
106108import org .springframework .data .elasticsearch .client .NoReachableHostException ;
107109import org .springframework .data .elasticsearch .client .reactive .HostProvider .Verification ;
110+ import org .springframework .data .elasticsearch .client .reactive .ReactiveElasticsearchClient .Cluster ;
108111import org .springframework .data .elasticsearch .client .reactive .ReactiveElasticsearchClient .Indices ;
109112import org .springframework .data .elasticsearch .client .util .NamedXContents ;
110113import org .springframework .data .elasticsearch .client .util .ScrollState ;
142145 * @see ClientConfiguration
143146 * @see ReactiveRestClients
144147 */
145- public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearchClient , Indices {
148+ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearchClient , Indices , Cluster {
146149
147150 private final HostProvider <?> hostProvider ;
148151 private final RequestCreator requestCreator ;
@@ -297,10 +300,6 @@ public void setHeadersSupplier(Supplier<HttpHeaders> headersSupplier) {
297300 this .headersSupplier = headersSupplier ;
298301 }
299302
300- /*
301- * (non-Javadoc)
302- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.http.HttpHeaders)
303- */
304303 @ Override
305304 public Mono <Boolean > ping (HttpHeaders headers ) {
306305
@@ -309,21 +308,13 @@ public Mono<Boolean> ping(HttpHeaders headers) {
309308 .onErrorResume (NoReachableHostException .class , error -> Mono .just (false )).next ();
310309 }
311310
312- /*
313- * (non-Javadoc)
314- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#info(org.springframework.http.HttpHeaders)
315- */
316311 @ Override
317312 public Mono <MainResponse > info (HttpHeaders headers ) {
318313
319314 return sendRequest (new MainRequest (), requestCreator .info (), MainResponse .class , headers ) //
320315 .next ();
321316 }
322317
323- /*
324- * (non-Javadoc)
325- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#get(org.springframework.http.HttpHeaders, org.elasticsearch.action.get.GetRequest)
326- */
327318 @ Override
328319 public Mono <GetResult > get (HttpHeaders headers , GetRequest getRequest ) {
329320
@@ -341,10 +332,6 @@ public Flux<MultiGetItemResponse> multiGet(HttpHeaders headers, MultiGetRequest
341332 .flatMap (Flux ::fromArray ); //
342333 }
343334
344- /*
345- * (non-Javadoc)
346- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#exists(org.springframework.http.HttpHeaders, org.elasticsearch.action.get.GetRequest)
347- */
348335 @ Override
349336 public Mono <Boolean > exists (HttpHeaders headers , GetRequest getRequest ) {
350337
@@ -353,48 +340,33 @@ public Mono<Boolean> exists(HttpHeaders headers, GetRequest getRequest) {
353340 .next ();
354341 }
355342
356- /*
357- * (non-Javadoc)
358- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.http.HttpHeaders, org.elasticsearch.action.index.IndexRequest)
359- */
360343 @ Override
361344 public Mono <IndexResponse > index (HttpHeaders headers , IndexRequest indexRequest ) {
362345 return sendRequest (indexRequest , requestCreator .index (), IndexResponse .class , headers ).next ();
363346 }
364347
365- /*
366- * (non-Javadoc)
367- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#indices()
368- */
369348 @ Override
370349 public Indices indices () {
371350 return this ;
372351 }
373352
374- /*
375- * (non-Javadoc)
376- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.http.HttpHeaders, org.elasticsearch.action.update.UpdateRequest)
377- */
353+ @ Override
354+ public Cluster cluster () {
355+ return this ;
356+ }
357+
378358 @ Override
379359 public Mono <UpdateResponse > update (HttpHeaders headers , UpdateRequest updateRequest ) {
380360 return sendRequest (updateRequest , requestCreator .update (), UpdateResponse .class , headers ).next ();
381361 }
382362
383- /*
384- * (non-Javadoc)
385- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.http.HttpHeaders, org.elasticsearch.action.delete.DeleteRequest)
386- */
387363 @ Override
388364 public Mono <DeleteResponse > delete (HttpHeaders headers , DeleteRequest deleteRequest ) {
389365
390366 return sendRequest (deleteRequest , requestCreator .delete (), DeleteResponse .class , headers ) //
391367 .next ();
392368 }
393369
394- /*
395- * (non-Javadoc)
396- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#count(org.springframework.http.HttpHeaders, org.elasticsearch.action.search.SearchRequest)
397- */
398370 @ Override
399371 public Mono <Long > count (HttpHeaders headers , SearchRequest searchRequest ) {
400372 searchRequest .source ().trackTotalHits (true );
@@ -412,10 +384,6 @@ public Flux<SearchHit> searchTemplate(HttpHeaders headers, SearchTemplateRequest
412384 .map (response -> response .getResponse ().getHits ()).flatMap (Flux ::fromIterable );
413385 }
414386
415- /*
416- * (non-Javadoc)
417- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.http.HttpHeaders, org.elasticsearch.action.search.SearchRequest)
418- */
419387 @ Override
420388 public Flux <SearchHit > search (HttpHeaders headers , SearchRequest searchRequest ) {
421389
@@ -435,10 +403,6 @@ public Flux<Suggest> suggest(HttpHeaders headers, SearchRequest searchRequest) {
435403 .map (SearchResponse ::getSuggest );
436404 }
437405
438- /*
439- * (non-Javadoc)
440- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#aggregate(org.springframework.http.HttpHeaders, org.elasticsearch.action.search.SearchRequest)
441- */
442406 @ Override
443407 public Flux <Aggregation > aggregate (HttpHeaders headers , SearchRequest searchRequest ) {
444408
@@ -453,10 +417,6 @@ public Flux<Aggregation> aggregate(HttpHeaders headers, SearchRequest searchRequ
453417 .flatMap (Flux ::fromIterable );
454418 }
455419
456- /*
457- * (non-Javadoc)
458- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#scroll(org.springframework.http.HttpHeaders, org.elasticsearch.action.search.SearchRequest)
459- */
460420 @ Override
461421 public Flux <SearchHit > scroll (HttpHeaders headers , SearchRequest searchRequest ) {
462422
@@ -506,10 +466,6 @@ private Publisher<?> cleanupScroll(HttpHeaders headers, ScrollState state) {
506466 return sendRequest (clearScrollRequest , requestCreator .clearScroll (), ClearScrollResponse .class , headers );
507467 }
508468
509- /*
510- * (non-Javadoc)
511- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.http.HttpHeaders, org.elasticsearch.index.reindex.DeleteByQueryRequest)
512- */
513469 @ Override
514470 public Mono <BulkByScrollResponse > deleteBy (HttpHeaders headers , DeleteByQueryRequest deleteRequest ) {
515471
@@ -524,10 +480,6 @@ public Mono<ByQueryResponse> updateBy(HttpHeaders headers, UpdateByQueryRequest
524480 .map (ByQueryResponse ::of );
525481 }
526482
527- /*
528- * (non-Javadoc)
529- * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#bulk(org.springframework.http.HttpHeaders, org.elasticsearch.action.bulk.BulkRequest)
530- */
531483 @ Override
532484 public Mono <BulkResponse > bulk (HttpHeaders headers , BulkRequest bulkRequest ) {
533485 return sendRequest (bulkRequest , requestCreator .bulk (), BulkResponse .class , headers ) //
@@ -812,6 +764,14 @@ public Mono<GetIndexResponse> getIndex(HttpHeaders headers, GetIndexRequest getI
812764
813765 // endregion
814766
767+ // region cluster operations
768+ @ Override
769+ public Mono <ClusterHealthResponse > health (HttpHeaders headers , ClusterHealthRequest clusterHealthRequest ) {
770+ return sendRequest (clusterHealthRequest , requestCreator .clusterHealth (), ClusterHealthResponse .class , headers )
771+ .next ();
772+ }
773+ // endregion
774+
815775 // region helper functions
816776 private <T > Publisher <? extends T > readResponseBody (String logId , Request request , ClientResponse response ,
817777 Class <T > responseType ) {
@@ -965,7 +925,7 @@ private static ElasticsearchException getElasticsearchException(String content,
965925 } while (token == XContentParser .Token .FIELD_NAME );
966926
967927 return null ;
968- } catch (IOException e ) {
928+ } catch (Exception e ) {
969929 return new ElasticsearchStatusException (content , status );
970930 }
971931 }
0 commit comments