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 |
|:-------------------------:|:-------------:|
| 3.2.x | 6.5.0 |
| 3.1.x | 6.2.2 |
| 3.0.x | 5.5.0 |
| 2.1.x | 2.4.0 |
@ -185,6 +186,78 @@ Searching entities using Elasticsearch Template
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
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.
*
* @author Mark Paluch
* @since 4.0
* @since 3.2
*/
public interface ClientConfiguration {

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ import org.springframework.util.Assert;
* Value Object containing information about Elasticsearch cluster nodes.
*
* @author Christoph Strobl
* @since 4.0
* @since 3.2
*/
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}.
*
* @author Mark Paluch
* @since 4.0
* @since 3.2
*/
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).
*
* @author Christoph Strobl
* @since 4.0
* @since 3.2
*/
public class NoReachableHostException extends RuntimeException {

View File

@ -52,7 +52,7 @@ import org.springframework.util.Assert;
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 4.0
* @since 3.2
*/
public final class RestClients {
@ -157,7 +157,7 @@ public final class RestClients {
* Logging interceptors for Elasticsearch client logging.
*
* @see ClientLogger
* @since 4.0
* @since 3.2
*/
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 Mark Paluch
* @since 4.0
* @since 3.2
* @see ClientConfiguration
* @see ReactiveRestClients
*/
@ -657,7 +657,7 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch
* Mutable state object holding scrollId to be used for {@link SearchScrollRequest#scroll(Scroll)}
*
* @author Christoph Strobl
* @since 4.0
* @since 3.2
*/
private static class ScrollState {

View File

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

View File

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

View File

@ -40,7 +40,7 @@ import org.springframework.web.reactive.function.client.WebClient;
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 4.0
* @since 3.2
*/
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}.
*
* @author Christoph Strobl
* @since 4.0
* @since 3.2
*/
class RawActionResponse extends ActionResponse implements ClientResponse {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -38,7 +38,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 4.0
* @since 3.2
*/
@RequiredArgsConstructor
class EntityOperations {
@ -270,7 +270,7 @@ class EntityOperations {
/**
* @param <T>
* @author Christoph Strobl
* @since 4.0
* @since 3.2
*/
@RequiredArgsConstructor
private static class MapBackedEntity<T extends Map<String, Object>> implements AdaptibleEntity<T> {
@ -377,7 +377,7 @@ class EntityOperations {
* Plain entity without applying further mapping.
*
* @param <T>
* @since 4.0
* @since 3.2
*/
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}.
*
* @param <T>
* @since 4.0
* @since 3.2
*/
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}.
*
* @param <T>
* @since 3.2
*/
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
private static class MappedEntity<T> implements Entity<T> {
@ -488,7 +489,7 @@ class EntityOperations {
/**
* @param <T>
* @since 4.0
* @since 3.2
*/
private static class AdaptibleMappedEntity<T> extends MappedEntity<T> implements AdaptibleEntity<T> {

View File

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

View File

@ -73,7 +73,7 @@ import org.springframework.util.ObjectUtils;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @since 4.0
* @since 3.2
*/
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 <T>
* @return can be {@literal null} if the {@link GetResult#isSourceEmpty() is empty}.
* @since 4.0
* @since 3.2
*/
@Nullable
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 <T>
* @return can be {@literal null} if the {@link SearchHit} does not have {@link SearchHit#hasSource() a source}.
* @since 4.0
* @since 3.2
*/
@Nullable
default <T> T mapEntity(SearchHit searchHit, Class<T> type) {

View File

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