|
48 | 48 | import org.elasticsearch.ElasticsearchStatusException;
|
49 | 49 | import org.elasticsearch.action.ActionRequest;
|
50 | 50 | import org.elasticsearch.action.ActionResponse;
|
| 51 | +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; |
| 52 | +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; |
| 53 | +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; |
| 54 | +import org.elasticsearch.action.admin.indices.flush.FlushRequest; |
| 55 | +import org.elasticsearch.action.admin.indices.flush.FlushResponse; |
| 56 | +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; |
| 57 | +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; |
| 58 | +import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; |
| 59 | +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; |
| 60 | +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; |
51 | 61 | import org.elasticsearch.action.delete.DeleteRequest;
|
52 | 62 | import org.elasticsearch.action.delete.DeleteResponse;
|
53 | 63 | import org.elasticsearch.action.get.GetRequest;
|
|
63 | 73 | import org.elasticsearch.action.search.SearchRequest;
|
64 | 74 | import org.elasticsearch.action.search.SearchResponse;
|
65 | 75 | import org.elasticsearch.action.search.SearchScrollRequest;
|
| 76 | +import org.elasticsearch.action.support.master.AcknowledgedResponse; |
66 | 77 | import org.elasticsearch.action.update.UpdateRequest;
|
67 | 78 | import org.elasticsearch.action.update.UpdateResponse;
|
68 | 79 | import org.elasticsearch.client.Request;
|
|
80 | 91 | import org.elasticsearch.search.SearchHit;
|
81 | 92 | import org.elasticsearch.search.SearchHits;
|
82 | 93 | import org.reactivestreams.Publisher;
|
83 |
| - |
84 | 94 | import org.springframework.data.elasticsearch.ElasticsearchException;
|
85 | 95 | import org.springframework.data.elasticsearch.client.ClientConfiguration;
|
86 | 96 | import org.springframework.data.elasticsearch.client.ClientLogger;
|
87 | 97 | import org.springframework.data.elasticsearch.client.ElasticsearchHost;
|
88 | 98 | import org.springframework.data.elasticsearch.client.NoReachableHostException;
|
89 | 99 | import org.springframework.data.elasticsearch.client.reactive.HostProvider.Verification;
|
| 100 | +import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices; |
90 | 101 | import org.springframework.data.elasticsearch.client.util.RequestConverters;
|
91 | 102 | import org.springframework.data.util.Lazy;
|
92 | 103 | import org.springframework.http.HttpHeaders;
|
|
115 | 126 | * @see ClientConfiguration
|
116 | 127 | * @see ReactiveRestClients
|
117 | 128 | */
|
118 |
| -public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearchClient { |
| 129 | +public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearchClient, Indices { |
119 | 130 |
|
120 | 131 | private final HostProvider hostProvider;
|
121 | 132 |
|
@@ -279,6 +290,15 @@ public Mono<IndexResponse> index(HttpHeaders headers, IndexRequest indexRequest)
|
279 | 290 | return sendRequest(indexRequest, RequestCreator.index(), IndexResponse.class, headers).publishNext();
|
280 | 291 | }
|
281 | 292 |
|
| 293 | + /* |
| 294 | + * (non-Javadoc) |
| 295 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#indices() |
| 296 | + */ |
| 297 | + @Override |
| 298 | + public Indices indices() { |
| 299 | + return this; |
| 300 | + } |
| 301 | + |
282 | 302 | /*
|
283 | 303 | * (non-Javadoc)
|
284 | 304 | * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.http.HttpHeaders, org.elasticsearch.action.update.UpdateRequest)
|
@@ -403,6 +423,97 @@ public Mono<BulkByScrollResponse> deleteBy(HttpHeaders headers, DeleteByQueryReq
|
403 | 423 | .publishNext();
|
404 | 424 | }
|
405 | 425 |
|
| 426 | + // --> INDICES |
| 427 | + |
| 428 | + /* |
| 429 | + * (non-Javadoc) |
| 430 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#existsIndex(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.get.GetIndexRequest) |
| 431 | + */ |
| 432 | + @Override |
| 433 | + public Mono<Boolean> existsIndex(HttpHeaders headers, GetIndexRequest request) { |
| 434 | + |
| 435 | + return sendRequest(request, RequestCreator.indexExists(), RawActionResponse.class, headers) // |
| 436 | + .map(response -> response.statusCode().is2xxSuccessful()) // |
| 437 | + .next(); |
| 438 | + } |
| 439 | + |
| 440 | + /* |
| 441 | + * (non-Javadoc) |
| 442 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#deleteIndex(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) |
| 443 | + */ |
| 444 | + @Override |
| 445 | + public Mono<Void> deleteIndex(HttpHeaders headers, DeleteIndexRequest request) { |
| 446 | + |
| 447 | + return sendRequest(request, RequestCreator.indexDelete(), AcknowledgedResponse.class, headers) // |
| 448 | + .then(); |
| 449 | + } |
| 450 | + |
| 451 | + /* |
| 452 | + * (non-Javadoc) |
| 453 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#createIndex(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.create.CreateIndexRequest) |
| 454 | + */ |
| 455 | + @Override |
| 456 | + public Mono<Void> createIndex(HttpHeaders headers, CreateIndexRequest createIndexRequest) { |
| 457 | + |
| 458 | + return sendRequest(createIndexRequest, RequestCreator.indexCreate(), AcknowledgedResponse.class, headers) // |
| 459 | + .then(); |
| 460 | + } |
| 461 | + |
| 462 | + /* |
| 463 | + * (non-Javadoc) |
| 464 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#openIndex(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.open.OpenIndexRequest) |
| 465 | + */ |
| 466 | + @Override |
| 467 | + public Mono<Void> openIndex(HttpHeaders headers, OpenIndexRequest request) { |
| 468 | + |
| 469 | + return sendRequest(request, RequestCreator.indexOpen(), AcknowledgedResponse.class, headers) // |
| 470 | + .then(); |
| 471 | + } |
| 472 | + |
| 473 | + /* |
| 474 | + * (non-Javadoc) |
| 475 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#closeIndex(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.close.CloseIndexRequest) |
| 476 | + */ |
| 477 | + @Override |
| 478 | + public Mono<Void> closeIndex(HttpHeaders headers, CloseIndexRequest closeIndexRequest) { |
| 479 | + |
| 480 | + return sendRequest(closeIndexRequest, RequestCreator.indexClose(), AcknowledgedResponse.class, headers) // |
| 481 | + .then(); |
| 482 | + } |
| 483 | + |
| 484 | + /* |
| 485 | + * (non-Javadoc) |
| 486 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#refreshIndex(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.refresh.RefreshRequest) |
| 487 | + */ |
| 488 | + @Override |
| 489 | + public Mono<Void> refreshIndex(HttpHeaders headers, RefreshRequest refreshRequest) { |
| 490 | + |
| 491 | + return sendRequest(refreshRequest, RequestCreator.indexRefresh(), RefreshResponse.class, headers) // |
| 492 | + .then(); |
| 493 | + } |
| 494 | + |
| 495 | + /* |
| 496 | + * (non-Javadoc) |
| 497 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#updateMapping(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) |
| 498 | + */ |
| 499 | + @Override |
| 500 | + public Mono<Void> updateMapping(HttpHeaders headers, PutMappingRequest putMappingRequest) { |
| 501 | + |
| 502 | + return sendRequest(putMappingRequest, RequestCreator.putMapping(), AcknowledgedResponse.class, headers) // |
| 503 | + .then(); |
| 504 | + } |
| 505 | + |
| 506 | + /* |
| 507 | + * (non-Javadoc) |
| 508 | + * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices#flushIndex(org.springframework.http.HttpHeaders, org.elasticsearch.action.admin.indices.flush.FlushRequest) |
| 509 | + */ |
| 510 | + @Override |
| 511 | + public Mono<Void> flushIndex(HttpHeaders headers, FlushRequest flushRequest) { |
| 512 | + |
| 513 | + return sendRequest(flushRequest, RequestCreator.flushIndex(), FlushResponse.class, headers) // |
| 514 | + .then(); |
| 515 | + } |
| 516 | + |
406 | 517 | /*
|
407 | 518 | * (non-Javadoc)
|
408 | 519 | * @see org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient#ping(org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.ReactiveElasticsearchClientCallback)
|
@@ -630,6 +741,41 @@ static Function<DeleteByQueryRequest, Request> deleteByQuery() {
|
630 | 741 | }
|
631 | 742 | };
|
632 | 743 | }
|
| 744 | + |
| 745 | + // --> INDICES |
| 746 | + |
| 747 | + static Function<GetIndexRequest, Request> indexExists() { |
| 748 | + return RequestConverters::indexExists; |
| 749 | + } |
| 750 | + |
| 751 | + static Function<DeleteIndexRequest, Request> indexDelete() { |
| 752 | + return RequestConverters::indexDelete; |
| 753 | + } |
| 754 | + |
| 755 | + static Function<CreateIndexRequest, Request> indexCreate() { |
| 756 | + return RequestConverters::indexCreate; |
| 757 | + } |
| 758 | + |
| 759 | + static Function<OpenIndexRequest, Request> indexOpen() { |
| 760 | + return RequestConverters::indexOpen; |
| 761 | + } |
| 762 | + |
| 763 | + static Function<CloseIndexRequest, Request> indexClose() { |
| 764 | + return RequestConverters::indexClose; |
| 765 | + } |
| 766 | + |
| 767 | + static Function<RefreshRequest, Request> indexRefresh() { |
| 768 | + return RequestConverters::indexRefresh; |
| 769 | + } |
| 770 | + |
| 771 | + static Function<PutMappingRequest, Request> putMapping() { |
| 772 | + return RequestConverters::putMapping; |
| 773 | + } |
| 774 | + |
| 775 | + static Function<FlushRequest, Request> flushIndex() { |
| 776 | + return RequestConverters::flushIndex; |
| 777 | + } |
| 778 | + |
633 | 779 | }
|
634 | 780 |
|
635 | 781 | /**
|
|
0 commit comments