DATAES-512 - Polishing.

Update Javadoc and Readme to reflect recent back ports.
This commit is contained in:
Christoph Strobl 2018-12-10 14:48:56 +01:00
parent a3a46b2e11
commit d8f43d3297
29 changed files with 114 additions and 40 deletions

View File

@ -54,6 +54,7 @@ the appropriate dependency version.
| spring data elasticsearch | elasticsearch | | spring data elasticsearch | elasticsearch |
|:-------------------------:|:-------------:| |:-------------------------:|:-------------:|
| 3.2.x | 6.5.0 |
| 3.1.x | 6.2.2 | | 3.1.x | 6.2.2 |
| 3.0.x | 5.5.0 | | 3.0.x | 5.5.0 |
| 2.1.x | 2.4.0 | | 2.1.x | 2.4.0 |
@ -185,6 +186,78 @@ Searching entities using Elasticsearch Template
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery,SampleEntity.class); Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery,SampleEntity.class);
``` ```
### Reactive Elasticsearch
The `ReactiveElasticsearchClient` is a non official driver based on `WebClient`.
It uses the request/response objects provided by the Elasticsearch core project.
```java
@Configuration
public class Config {
@Bean
ReactiveElasticsearchClient client() {
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:9200", "localhost:9291")
.build();
return ReactiveRestClients.create(clientConfiguration);
}
}
// ...
Mono<IndexResponse> response = client.index(request ->
request.index("spring-data")
.type("elasticsearch")
.id(randomID())
.source(singletonMap("feature", "reactive-client"))
.setRefreshPolicy(IMMEDIATE)
);
```
The reactive client response, especially for search operations, is bound to the `from` (offset) & `size` (limit) options of the request.
`ReactiveElasticsearchOperations` is the gateway to executing high level commands against an Elasticsearch cluster using the `ReactiveElasticsearchClient`.
The easiest way of setting up the `ReactiveElasticsearchTemplate` is via `AbstractReactiveElasticsearchConfiguration`.
```java
@Configuration
public class Config extends AbstractReactiveElasticsearchConfiguration {
@Bean
@Override
public ReactiveElasticsearchClient reactiveElasticsearchClient() {
// ...
}
}
```
If needed the `ReactiveElasticsearchTemplate` can be configured with default `RefreshPolicy` and `IndicesOptions` that get applied to the related requests by overriding the defaults of `refreshPolicy()` and `indicesOptions()`.
```java
template.save(new Person("Bruce Banner", 42))
.doOnNext(System.out::println)
.flatMap(person -> template.findById(person.id, Person.class))
.doOnNext(System.out::println)
.flatMap(person -> template.delete(person))
.doOnNext(System.out::println)
.flatMap(id -> template.count(Person.class))
.doOnNext(System.out::println)
.subscribe();
```
The above outputs the following sequence on the console.
```bash
> Person(id=QjWCWWcBXiLAnp77ksfR, name=Bruce Banner, age=42)
> Person(id=QjWCWWcBXiLAnp77ksfR, name=Bruce Banner, age=42)
> QjWCWWcBXiLAnp77ksfR
> 0
```
### XML Namespace ### XML Namespace
You can set up repository scanning via xml configuration, which will happily create your repositories. You can set up repository scanning via xml configuration, which will happily create your repositories.

View File

@ -29,7 +29,7 @@ import org.springframework.http.HttpHeaders;
* Configuration interface exposing common client configuration properties for Elasticsearch clients. * Configuration interface exposing common client configuration properties for Elasticsearch clients.
* *
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
public interface ClientConfiguration { public interface ClientConfiguration {

View File

@ -36,7 +36,7 @@ import org.springframework.util.Assert;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
class ClientConfigurationBuilder class ClientConfigurationBuilder
implements ClientConfigurationBuilderWithRequiredEndpoint, MaybeSecureClientConfigurationBuilder { implements ClientConfigurationBuilderWithRequiredEndpoint, MaybeSecureClientConfigurationBuilder {

View File

@ -29,7 +29,7 @@ import org.springframework.util.ObjectUtils;
* *
* @author Mark Paluch * @author Mark Paluch
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
public abstract class ClientLogger { public abstract class ClientLogger {

View File

@ -32,7 +32,7 @@ import org.springframework.lang.Nullable;
* *
* @author Mark Paluch * @author Mark Paluch
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
class DefaultClientConfiguration implements ClientConfiguration { class DefaultClientConfiguration implements ClientConfiguration {

View File

@ -25,7 +25,7 @@ import org.springframework.util.Assert;
* Value Object containing information about Elasticsearch cluster nodes. * Value Object containing information about Elasticsearch cluster nodes.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
public class ElasticsearchHost { public class ElasticsearchHost {

View File

@ -24,7 +24,7 @@ import org.springframework.util.StringUtils;
* Utility to parse endpoints in {@code host:port} format into {@link java.net.InetSocketAddress}. * Utility to parse endpoints in {@code host:port} format into {@link java.net.InetSocketAddress}.
* *
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
class InetSocketAddressParser { class InetSocketAddressParser {

View File

@ -22,7 +22,7 @@ import java.util.Set;
* {@link RuntimeException} to be emitted / thrown when the cluster is down (aka none of the known nodes is reachable). * {@link RuntimeException} to be emitted / thrown when the cluster is down (aka none of the known nodes is reachable).
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
public class NoReachableHostException extends RuntimeException { public class NoReachableHostException extends RuntimeException {

View File

@ -52,7 +52,7 @@ import org.springframework.util.Assert;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
public final class RestClients { public final class RestClients {
@ -157,7 +157,7 @@ public final class RestClients {
* Logging interceptors for Elasticsearch client logging. * Logging interceptors for Elasticsearch client logging.
* *
* @see ClientLogger * @see ClientLogger
* @since 4.0 * @since 3.2
*/ */
private static class HttpLoggingInterceptor implements HttpResponseInterceptor, HttpRequestInterceptor { private static class HttpLoggingInterceptor implements HttpResponseInterceptor, HttpRequestInterceptor {

View File

@ -110,7 +110,7 @@ import org.springframework.web.reactive.function.client.WebClient.RequestBodySpe
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
* @see ClientConfiguration * @see ClientConfiguration
* @see ReactiveRestClients * @see ReactiveRestClients
*/ */
@ -657,7 +657,7 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch
* Mutable state object holding scrollId to be used for {@link SearchScrollRequest#scroll(Scroll)} * Mutable state object holding scrollId to be used for {@link SearchScrollRequest#scroll(Scroll)}
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
private static class ScrollState { private static class ScrollState {

View File

@ -32,7 +32,7 @@ import org.springframework.web.reactive.function.client.WebClient.Builder;
* *
* @author Mark Paluch * @author Mark Paluch
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
class DefaultWebClientProvider implements WebClientProvider { class DefaultWebClientProvider implements WebClientProvider {

View File

@ -32,7 +32,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
public interface HostProvider { public interface HostProvider {
@ -113,7 +113,7 @@ public interface HostProvider {
* {@link Verification} allows to influence the lookup strategy for active hosts. * {@link Verification} allows to influence the lookup strategy for active hosts.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
enum Verification { enum Verification {
@ -132,7 +132,7 @@ public interface HostProvider {
* Value object accumulating information about an Elasticsearch cluster. * Value object accumulating information about an Elasticsearch cluster.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0. * @since 3.2
*/ */
class ClusterInformation { class ClusterInformation {

View File

@ -40,7 +40,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
class MultiNodeHostProvider implements HostProvider { class MultiNodeHostProvider implements HostProvider {

View File

@ -35,7 +35,7 @@ import org.springframework.web.reactive.function.client.ExchangeStrategies;
* Extension to {@link ActionResponse} that also implements {@link ClientResponse}. * Extension to {@link ActionResponse} that also implements {@link ClientResponse}.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
class RawActionResponse extends ActionResponse implements ClientResponse { class RawActionResponse extends ActionResponse implements ClientResponse {

View File

@ -49,7 +49,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
* @see ClientConfiguration * @see ClientConfiguration
* @see ReactiveRestClients * @see ReactiveRestClients
*/ */
@ -438,7 +438,7 @@ public interface ReactiveElasticsearchClient {
* Low level callback interface operating upon {@link WebClient} to send commands towards elasticsearch. * Low level callback interface operating upon {@link WebClient} to send commands towards elasticsearch.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
interface ReactiveElasticsearchClientCallback { interface ReactiveElasticsearchClientCallback {
Mono<ClientResponse> doWithClient(WebClient client); Mono<ClientResponse> doWithClient(WebClient client);
@ -448,7 +448,7 @@ public interface ReactiveElasticsearchClient {
* Cumulative client {@link ElasticsearchHost} information. * Cumulative client {@link ElasticsearchHost} information.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
interface Status { interface Status {

View File

@ -24,7 +24,7 @@ import org.springframework.util.Assert;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
public final class ReactiveRestClients { public final class ReactiveRestClients {

View File

@ -22,7 +22,7 @@ import org.springframework.web.reactive.function.client.WebClientException;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
public class RequestBodyEncodingException extends WebClientException { public class RequestBodyEncodingException extends WebClientException {

View File

@ -30,7 +30,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
class SingleNodeHostProvider implements HostProvider { class SingleNodeHostProvider implements HostProvider {

View File

@ -34,7 +34,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* *
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
public interface WebClientProvider { public interface WebClientProvider {

View File

@ -87,7 +87,7 @@ import org.springframework.http.HttpMethod;
* </p> * </p>
* Modified for usage with {@link ReactiveElasticsearchClient}. * Modified for usage with {@link ReactiveElasticsearchClient}.
* *
* @since 4.0 * @since 3.2
*/ */
public class RequestConverters { public class RequestConverters {

View File

@ -22,7 +22,7 @@ import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
/** /**
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
* @see ElasticsearchConfigurationSupport * @see ElasticsearchConfigurationSupport
*/ */
public abstract class AbstractElasticsearchConfiguration extends ElasticsearchConfigurationSupport { public abstract class AbstractElasticsearchConfiguration extends ElasticsearchConfigurationSupport {

View File

@ -26,7 +26,7 @@ import org.springframework.lang.Nullable;
/** /**
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
* @see ElasticsearchConfigurationSupport * @see ElasticsearchConfigurationSupport
*/ */
@Configuration @Configuration

View File

@ -39,7 +39,7 @@ import org.springframework.util.StringUtils;
/** /**
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
@Configuration @Configuration
public class ElasticsearchConfigurationSupport { public class ElasticsearchConfigurationSupport {

View File

@ -25,7 +25,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
/** /**
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
public class ElasticsearchExceptionTranslator implements PersistenceExceptionTranslator { public class ElasticsearchExceptionTranslator implements PersistenceExceptionTranslator {

View File

@ -38,7 +38,7 @@ import org.springframework.util.StringUtils;
* *
* @author Mark Paluch * @author Mark Paluch
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
class EntityOperations { class EntityOperations {
@ -270,7 +270,7 @@ class EntityOperations {
/** /**
* @param <T> * @param <T>
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
private static class MapBackedEntity<T extends Map<String, Object>> implements AdaptibleEntity<T> { private static class MapBackedEntity<T extends Map<String, Object>> implements AdaptibleEntity<T> {
@ -377,7 +377,7 @@ class EntityOperations {
* Plain entity without applying further mapping. * Plain entity without applying further mapping.
* *
* @param <T> * @param <T>
* @since 4.0 * @since 3.2
*/ */
private static class UnmappedEntity<T extends Map<String, Object>> extends MapBackedEntity<T> { private static class UnmappedEntity<T extends Map<String, Object>> extends MapBackedEntity<T> {
@ -390,7 +390,7 @@ class EntityOperations {
* Simple mapped entity without an associated {@link ElasticsearchPersistentEntity}. * Simple mapped entity without an associated {@link ElasticsearchPersistentEntity}.
* *
* @param <T> * @param <T>
* @since 4.0 * @since 3.2
*/ */
private static class SimpleMappedEntity<T extends Map<String, Object>> extends MapBackedEntity<T> { private static class SimpleMappedEntity<T extends Map<String, Object>> extends MapBackedEntity<T> {
@ -412,6 +412,7 @@ class EntityOperations {
* Mapped entity with an associated {@link ElasticsearchPersistentEntity}. * Mapped entity with an associated {@link ElasticsearchPersistentEntity}.
* *
* @param <T> * @param <T>
* @since 3.2
*/ */
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) @RequiredArgsConstructor(access = AccessLevel.PROTECTED)
private static class MappedEntity<T> implements Entity<T> { private static class MappedEntity<T> implements Entity<T> {
@ -488,7 +489,7 @@ class EntityOperations {
/** /**
* @param <T> * @param <T>
* @since 4.0 * @since 3.2
*/ */
private static class AdaptibleMappedEntity<T> extends MappedEntity<T> implements AdaptibleEntity<T> { private static class AdaptibleMappedEntity<T> extends MappedEntity<T> implements AdaptibleEntity<T> {

View File

@ -35,7 +35,7 @@ import org.springframework.util.Assert;
* {@link Publisher}. * {@link Publisher}.
* *
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
public interface ReactiveElasticsearchOperations { public interface ReactiveElasticsearchOperations {
@ -450,7 +450,7 @@ public interface ReactiveElasticsearchOperations {
* *
* @param <T> * @param <T>
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
interface ClientCallback<T extends Publisher<?>> { interface ClientCallback<T extends Publisher<?>> {

View File

@ -73,7 +73,7 @@ import org.springframework.util.ObjectUtils;
/** /**
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @since 4.0 * @since 3.2
*/ */
public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOperations { public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOperations {

View File

@ -55,7 +55,7 @@ public interface ResultsMapper extends SearchResultMapper, GetResultMapper, Mult
* @param type must not be {@literal null}. * @param type must not be {@literal null}.
* @param <T> * @param <T>
* @return can be {@literal null} if the {@link GetResult#isSourceEmpty() is empty}. * @return can be {@literal null} if the {@link GetResult#isSourceEmpty() is empty}.
* @since 4.0 * @since 3.2
*/ */
@Nullable @Nullable
default <T> T mapEntity(GetResult getResult, Class<T> type) { default <T> T mapEntity(GetResult getResult, Class<T> type) {
@ -80,7 +80,7 @@ public interface ResultsMapper extends SearchResultMapper, GetResultMapper, Mult
* @param type must not be {@literal null}. * @param type must not be {@literal null}.
* @param <T> * @param <T>
* @return can be {@literal null} if the {@link SearchHit} does not have {@link SearchHit#hasSource() a source}. * @return can be {@literal null} if the {@link SearchHit} does not have {@link SearchHit#hasSource() a source}.
* @since 4.0 * @since 3.2
*/ */
@Nullable @Nullable
default <T> T mapEntity(SearchHit searchHit, Class<T> type) { default <T> T mapEntity(SearchHit searchHit, Class<T> type) {

View File

@ -21,7 +21,7 @@ import org.springframework.data.convert.CustomConversions;
/** /**
* @author Christoph Strobl * @author Christoph Strobl
* @since 4.0 * @since 3.2
*/ */
public class ElasticsearchCustomConversions extends CustomConversions { public class ElasticsearchCustomConversions extends CustomConversions {