mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-23 20:42:11 +00:00
parent
2cd18178e3
commit
35e9b691bd
@ -34,7 +34,6 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste
|
|||||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@ -53,6 +52,9 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
|
|||||||
protected ElasticsearchConverter elasticsearchConverter;
|
protected ElasticsearchConverter elasticsearchConverter;
|
||||||
protected RequestFactory requestFactory;
|
protected RequestFactory requestFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
public RequestFactory getRequestFactory() {
|
public RequestFactory getRequestFactory() {
|
||||||
return requestFactory;
|
return requestFactory;
|
||||||
}
|
}
|
||||||
@ -197,43 +199,6 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param query
|
|
||||||
* @param clazz
|
|
||||||
* @deprecated index names and types should not be set in query
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected void setPersistentEntityIndexAndType(Query query, Class clazz) {
|
|
||||||
if (query.getIndices().isEmpty()) {
|
|
||||||
String[] indices = retrieveIndexNameFromPersistentEntity(clazz);
|
|
||||||
|
|
||||||
if (indices != null) {
|
|
||||||
query.addIndices(indices);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (query.getTypes().isEmpty()) {
|
|
||||||
String[] types = retrieveTypeFromPersistentEntity(clazz);
|
|
||||||
|
|
||||||
if (types != null) {
|
|
||||||
query.addTypes(types);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] retrieveIndexNameFromPersistentEntity(Class clazz) {
|
|
||||||
if (clazz != null) {
|
|
||||||
return new String[] { getPersistentEntityFor(clazz).getIndexName() };
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] retrieveTypeFromPersistentEntity(Class clazz) {
|
|
||||||
if (clazz != null) {
|
|
||||||
return new String[] { getPersistentEntityFor(clazz).getIndexType() };
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> List<Page<T>> queryForPage(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index) {
|
public <T> List<Page<T>> queryForPage(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index) {
|
||||||
MultiSearchRequest request = new MultiSearchRequest();
|
MultiSearchRequest request = new MultiSearchRequest();
|
||||||
|
@ -483,11 +483,6 @@ public interface ElasticsearchOperations {
|
|||||||
*/
|
*/
|
||||||
ElasticsearchConverter getElasticsearchConverter();
|
ElasticsearchConverter getElasticsearchConverter();
|
||||||
|
|
||||||
/**
|
|
||||||
* @since 4.0
|
|
||||||
*/
|
|
||||||
RequestFactory getRequestFactory();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param clazz
|
* @param clazz
|
||||||
* @return the IndexCoordinates defined on the entity.
|
* @return the IndexCoordinates defined on the entity.
|
||||||
|
@ -23,6 +23,7 @@ import org.reactivestreams.Publisher;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||||
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
@ -72,35 +73,7 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Mono} emitting the saved entity.
|
* @return a {@link Mono} emitting the saved entity.
|
||||||
*/
|
*/
|
||||||
default <T> Mono<T> save(T entity) {
|
default <T> Mono<T> save(T entity) {
|
||||||
return save(entity, null);
|
return save(entity, getIndexCoordinatesFor(entity.getClass()));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Index the entity, once available, in the given {@literal index}. If the index is {@literal null} or empty the index
|
|
||||||
* name provided via entity metadata is used.
|
|
||||||
*
|
|
||||||
* @param entityPublisher must not be {@literal null}.
|
|
||||||
* @param index the name of the target index. Can be {@literal null}.
|
|
||||||
* @param <T>
|
|
||||||
* @return a {@link Mono} emitting the saved entity.
|
|
||||||
*/
|
|
||||||
default <T> Mono<T> save(Mono<? extends T> entityPublisher, String index) {
|
|
||||||
|
|
||||||
Assert.notNull(entityPublisher, "EntityPublisher must not be null!");
|
|
||||||
return entityPublisher.flatMap(it -> save(it, index));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Index the entity in the given {@literal index}. If the index is {@literal null} or empty the index name provided
|
|
||||||
* via entity metadata is used.
|
|
||||||
*
|
|
||||||
* @param entity must not be {@literal null}.
|
|
||||||
* @param index the name of the target index. Can be {@literal null}.
|
|
||||||
* @param <T>
|
|
||||||
* @return a {@link Mono} emitting the saved entity.
|
|
||||||
*/
|
|
||||||
default <T> Mono<T> save(T entity, @Nullable String index) {
|
|
||||||
return save(entity, index, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,15 +82,14 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* {@literal type}.
|
* {@literal type}.
|
||||||
*
|
*
|
||||||
* @param entityPublisher must not be {@literal null}.
|
* @param entityPublisher must not be {@literal null}.
|
||||||
* @param index the name of the target index. Can be {@literal null}.
|
* @param index the target index, must not be {@literal null}
|
||||||
* @param type the name of the type within the index. Can be {@literal null}.
|
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @return a {@link Mono} emitting the saved entity.
|
* @return a {@link Mono} emitting the saved entity.
|
||||||
*/
|
*/
|
||||||
default <T> Mono<T> save(Mono<? extends T> entityPublisher, @Nullable String index, @Nullable String type) {
|
default <T> Mono<T> save(Mono<? extends T> entityPublisher, IndexCoordinates index) {
|
||||||
|
|
||||||
Assert.notNull(entityPublisher, "EntityPublisher must not be null!");
|
Assert.notNull(entityPublisher, "EntityPublisher must not be null!");
|
||||||
return entityPublisher.flatMap(it -> save(it, index, type));
|
return entityPublisher.flatMap(it -> save(it, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,12 +97,11 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* {@literal null} or empty the index name provided via entity metadata is used. Same for the {@literal type}.
|
* {@literal null} or empty the index name provided via entity metadata is used. Same for the {@literal type}.
|
||||||
*
|
*
|
||||||
* @param entity must not be {@literal null}.
|
* @param entity must not be {@literal null}.
|
||||||
* @param index the name of the target index. Can be {@literal null}.
|
* @param index the target index, must not be {@literal null}
|
||||||
* @param type the name of the type within the index. Can be {@literal null}.
|
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @return a {@link Mono} emitting the saved entity.
|
* @return a {@link Mono} emitting the saved entity.
|
||||||
*/
|
*/
|
||||||
<T> Mono<T> save(T entity, @Nullable String index, @Nullable String type);
|
<T> Mono<T> save(T entity, IndexCoordinates index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the document with the given {@literal id} mapped onto the given {@literal entityType}.
|
* Find the document with the given {@literal id} mapped onto the given {@literal entityType}.
|
||||||
@ -141,35 +112,18 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return {@link Mono#empty()} if not found.
|
* @return {@link Mono#empty()} if not found.
|
||||||
*/
|
*/
|
||||||
default <T> Mono<T> findById(String id, Class<T> entityType) {
|
default <T> Mono<T> findById(String id, Class<T> entityType) {
|
||||||
return findById(id, entityType, null);
|
return findById(id, entityType, getIndexCoordinatesFor(entityType));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the entity with given {@literal id}.
|
|
||||||
*
|
|
||||||
* @param id the {@literal _id} of the document to fetch.
|
|
||||||
* @param entityType the domain type used for mapping the document.
|
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param <T>
|
|
||||||
* @return {@link Mono#empty()} if not found.
|
|
||||||
*/
|
|
||||||
default <T> Mono<T> findById(String id, Class<T> entityType, @Nullable String index) {
|
|
||||||
return findById(id, entityType, index, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the entity with given {@literal id}.
|
* Fetch the entity with given {@literal id}.
|
||||||
*
|
*
|
||||||
* @param id must not be {@literal null}.
|
* @param id must not be {@literal null}.
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
* @param index the target index, must not be {@literal null}
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @return the {@link Mono} emitting the entity or signalling completion if none found.
|
* @return the {@link Mono} emitting the entity or signalling completion if none found.
|
||||||
*/
|
*/
|
||||||
<T> Mono<T> findById(String id, Class<T> entityType, @Nullable String index, @Nullable String type);
|
<T> Mono<T> findById(String id, Class<T> entityType, IndexCoordinates index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an entity with given {@literal id} exists.
|
* Check if an entity with given {@literal id} exists.
|
||||||
@ -179,33 +133,17 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Mono} emitting {@literal true} if a matching document exists, {@literal false} otherwise.
|
* @return a {@link Mono} emitting {@literal true} if a matching document exists, {@literal false} otherwise.
|
||||||
*/
|
*/
|
||||||
default Mono<Boolean> exists(String id, Class<?> entityType) {
|
default Mono<Boolean> exists(String id, Class<?> entityType) {
|
||||||
return exists(id, entityType, null);
|
return exists(id, entityType, getIndexCoordinatesFor(entityType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an entity with given {@literal id} exists.
|
* Check if an entity with given {@literal id} exists.
|
||||||
*
|
*
|
||||||
* @param id the {@literal _id} of the document to look for.
|
* @param id the {@literal _id} of the document to look for.
|
||||||
* @param entityType the domain type used.
|
* @param index the target index, must not be {@literal null}
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting {@literal true} if a matching document exists, {@literal false} otherwise.
|
* @return a {@link Mono} emitting {@literal true} if a matching document exists, {@literal false} otherwise.
|
||||||
*/
|
*/
|
||||||
default Mono<Boolean> exists(String id, Class<?> entityType, @Nullable String index) {
|
Mono<Boolean> exists(String id, Class<?> entityType, IndexCoordinates index);
|
||||||
return exists(id, entityType, index, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if an entity with given {@literal id} exists.
|
|
||||||
*
|
|
||||||
* @param id the {@literal _id} of the document to look for.
|
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting {@literal true} if a matching document exists, {@literal false} otherwise.
|
|
||||||
*/
|
|
||||||
Mono<Boolean> exists(String id, Class<?> entityType, @Nullable String index, @Nullable String type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search the index for entities matching the given {@link Query query}. <br />
|
* Search the index for entities matching the given {@link Query query}. <br />
|
||||||
@ -235,7 +173,7 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Flux} emitting matching entities one by one.
|
* @return a {@link Flux} emitting matching entities one by one.
|
||||||
*/
|
*/
|
||||||
default <T> Flux<T> find(Query query, Class<?> entityType, Class<T> returnType) {
|
default <T> Flux<T> find(Query query, Class<?> entityType, Class<T> returnType) {
|
||||||
return find(query, entityType, null, null, returnType);
|
return find(query, entityType, returnType, getIndexCoordinatesFor(entityType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,27 +181,12 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
*
|
*
|
||||||
* @param query must not be {@literal null}.
|
* @param query must not be {@literal null}.
|
||||||
* @param entityType must not be {@literal null}.
|
* @param entityType must not be {@literal null}.
|
||||||
* @param <T>
|
* @param index the target index, must not be {@literal null}
|
||||||
* @return a {@link Flux} emitting matching entities one by one.
|
|
||||||
*/
|
|
||||||
default <T> Flux<T> find(Query query, Class<T> entityType, @Nullable String index) {
|
|
||||||
return find(query, entityType, index, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search the index for entities matching the given {@link Query query}.
|
|
||||||
*
|
|
||||||
* @param query must not be {@literal null}.
|
|
||||||
* @param entityType must not be {@literal null}.
|
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @returnm a {@link Flux} emitting matching entities one by one.
|
* @returnm a {@link Flux} emitting matching entities one by one.
|
||||||
*/
|
*/
|
||||||
default <T> Flux<T> find(Query query, Class<T> entityType, @Nullable String index, @Nullable String type) {
|
default <T> Flux<T> find(Query query, Class<T> entityType, IndexCoordinates index) {
|
||||||
return find(query, entityType, index, type, entityType);
|
return find(query, entityType, entityType, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -271,16 +194,12 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
*
|
*
|
||||||
* @param query must not be {@literal null}.
|
* @param query must not be {@literal null}.
|
||||||
* @param entityType must not be {@literal null}.
|
* @param entityType must not be {@literal null}.
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param resultType the projection result type.
|
* @param resultType the projection result type.
|
||||||
|
* @param index the target index, must not be {@literal null}
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @return a {@link Flux} emitting matching entities one by one.
|
* @return a {@link Flux} emitting matching entities one by one.
|
||||||
*/
|
*/
|
||||||
<T> Flux<T> find(Query query, Class<?> entityType, @Nullable String index, @Nullable String type,
|
<T> Flux<T> find(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index);
|
||||||
Class<T> resultType);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count the number of documents matching the given {@link Query}.
|
* Count the number of documents matching the given {@link Query}.
|
||||||
@ -289,7 +208,7 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Mono} emitting the nr of matching documents.
|
* @return a {@link Mono} emitting the nr of matching documents.
|
||||||
*/
|
*/
|
||||||
default Mono<Long> count(Class<?> entityType) {
|
default Mono<Long> count(Class<?> entityType) {
|
||||||
return count(new StringQuery(QueryBuilders.matchAllQuery().toString()), entityType, null);
|
return count(new StringQuery(QueryBuilders.matchAllQuery().toString()), entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -300,7 +219,7 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Mono} emitting the nr of matching documents.
|
* @return a {@link Mono} emitting the nr of matching documents.
|
||||||
*/
|
*/
|
||||||
default Mono<Long> count(Query query, Class<?> entityType) {
|
default Mono<Long> count(Query query, Class<?> entityType) {
|
||||||
return count(query, entityType, null);
|
return count(query, entityType, getIndexCoordinatesFor(entityType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -308,26 +227,10 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
*
|
*
|
||||||
* @param query must not be {@literal null}.
|
* @param query must not be {@literal null}.
|
||||||
* @param entityType must not be {@literal null}.
|
* @param entityType must not be {@literal null}.
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
* @param index the target index, must not be {@literal null}
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the nr of matching documents.
|
* @return a {@link Mono} emitting the nr of matching documents.
|
||||||
*/
|
*/
|
||||||
default Mono<Long> count(Query query, Class<?> entityType, @Nullable String index) {
|
Mono<Long> count(Query query, Class<?> entityType, IndexCoordinates index);
|
||||||
return count(query, entityType, index, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Count the number of documents matching the given {@link Query}.
|
|
||||||
*
|
|
||||||
* @param query must not be {@literal null}.
|
|
||||||
* @param entityType must not be {@literal null}.
|
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the nr of matching documents.
|
|
||||||
*/
|
|
||||||
Mono<Long> count(Query query, Class<?> entityType, @Nullable String index, @Nullable String type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the given entity extracting index and type from entity metadata.
|
* Delete the given entity extracting index and type from entity metadata.
|
||||||
@ -336,47 +239,30 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
||||||
*/
|
*/
|
||||||
default Mono<String> delete(Object entity) {
|
default Mono<String> delete(Object entity) {
|
||||||
return delete(entity, null);
|
return delete(entity, getIndexCoordinatesFor(entity.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the given entity extracting index and type from entity metadata.
|
* Delete the given entity extracting index and type from entity metadata.
|
||||||
*
|
*
|
||||||
* @param entity must not be {@literal null}.
|
* @param entity must not be {@literal null}.
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
* @param index the target index, must not be {@literal null}
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
||||||
*/
|
*/
|
||||||
default Mono<String> delete(Object entity, @Nullable String index) {
|
Mono<String> delete(Object entity, IndexCoordinates index);
|
||||||
return delete(entity, index, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the given entity extracting index and type from entity metadata.
|
|
||||||
*
|
|
||||||
* @param entity must not be {@literal null}.
|
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
|
||||||
*/
|
|
||||||
Mono<String> delete(Object entity, @Nullable String index, @Nullable String type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the entity with given {@literal id}.
|
* Delete the entity with given {@literal id}.
|
||||||
*
|
*
|
||||||
* @param id must not be {@literal null}.
|
* @param id must not be {@literal null}.
|
||||||
* @param index the name of the target index.
|
* @param index the target index, must not be {@literal null}
|
||||||
* @param type the name of the target type.
|
|
||||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
||||||
*/
|
*/
|
||||||
default Mono<String> deleteById(String id, String index, String type) {
|
default Mono<String> deleteById(String id, IndexCoordinates index) {
|
||||||
|
|
||||||
Assert.notNull(index, "Index must not be null!");
|
Assert.notNull(index, "Index must not be null!");
|
||||||
Assert.notNull(type, "Type must not be null!");
|
|
||||||
|
|
||||||
return deleteById(id, Object.class, index, type);
|
return deleteById(id, Object.class, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,7 +273,7 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
||||||
*/
|
*/
|
||||||
default Mono<String> deleteById(String id, Class<?> entityType) {
|
default Mono<String> deleteById(String id, Class<?> entityType) {
|
||||||
return deleteById(id, entityType, null);
|
return deleteById(id, entityType, getIndexCoordinatesFor(entityType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -395,26 +281,10 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
*
|
*
|
||||||
* @param id must not be {@literal null}.
|
* @param id must not be {@literal null}.
|
||||||
* @param entityType must not be {@literal null}.
|
* @param entityType must not be {@literal null}.
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
* @param index the target index, must not be {@literal null}
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
||||||
*/
|
*/
|
||||||
default Mono<String> deleteById(String id, Class<?> entityType, @Nullable String index) {
|
Mono<String> deleteById(String id, Class<?> entityType, IndexCoordinates index);
|
||||||
return deleteById(id, entityType, index, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the entity with given {@literal id} extracting index and type from entity metadata.
|
|
||||||
*
|
|
||||||
* @param id must not be {@literal null}.
|
|
||||||
* @param entityType must not be {@literal null}.
|
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the {@literal id} of the removed document.
|
|
||||||
*/
|
|
||||||
Mono<String> deleteById(String id, Class<?> entityType, @Nullable String index, @Nullable String type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the documents matching the given {@link Query} extracting index and type from entity metadata.
|
* Delete the documents matching the given {@link Query} extracting index and type from entity metadata.
|
||||||
@ -424,7 +294,7 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
* @return a {@link Mono} emitting the number of the removed documents.
|
* @return a {@link Mono} emitting the number of the removed documents.
|
||||||
*/
|
*/
|
||||||
default Mono<Long> deleteBy(Query query, Class<?> entityType) {
|
default Mono<Long> deleteBy(Query query, Class<?> entityType) {
|
||||||
return deleteBy(query, entityType, null);
|
return deleteBy(query, entityType, getIndexCoordinatesFor(entityType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -432,26 +302,10 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
*
|
*
|
||||||
* @param query must not be {@literal null}.
|
* @param query must not be {@literal null}.
|
||||||
* @param entityType must not be {@literal null}.
|
* @param entityType must not be {@literal null}.
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
* @param index the target index, must not be {@literal null}
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the number of the removed documents.
|
* @return a {@link Mono} emitting the number of the removed documents.
|
||||||
*/
|
*/
|
||||||
default Mono<Long> deleteBy(Query query, Class<?> entityType, @Nullable String index) {
|
Mono<Long> deleteBy(Query query, Class<?> entityType, IndexCoordinates index);
|
||||||
return deleteBy(query, entityType, index, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the documents matching the given {@link Query} extracting index and type from entity metadata.
|
|
||||||
*
|
|
||||||
* @param query must not be {@literal null}.
|
|
||||||
* @param entityType must not be {@literal null}.
|
|
||||||
* @param index the name of the target index. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @param type the name of the target type. Overwrites document metadata from {@literal entityType} if not
|
|
||||||
* {@literal null}.
|
|
||||||
* @return a {@link Mono} emitting the number of the removed documents.
|
|
||||||
*/
|
|
||||||
Mono<Long> deleteBy(Query query, Class<?> entityType, @Nullable String index, @Nullable String type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link ElasticsearchConverter} used.
|
* Get the {@link ElasticsearchConverter} used.
|
||||||
@ -460,6 +314,19 @@ public interface ReactiveElasticsearchOperations {
|
|||||||
*/
|
*/
|
||||||
ElasticsearchConverter getElasticsearchConverter();
|
ElasticsearchConverter getElasticsearchConverter();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
ElasticsearchPersistentEntity<?> getPersistentEntityFor(Class<?> clazz);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clazz
|
||||||
|
* @return the IndexCoordinates defined on the entity.
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
default IndexCoordinates getIndexCoordinatesFor(Class<?> clazz) {
|
||||||
|
ElasticsearchPersistentEntity entity = getPersistentEntityFor(clazz);
|
||||||
|
return IndexCoordinates.of(entity.getIndexName()).withTypes(entity.getIndexType());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback interface to be used with {@link #execute(ClientCallback)} for operating directly on
|
* Callback interface to be used with {@link #execute(ClientCallback)} for operating directly on
|
||||||
* {@link ReactiveElasticsearchClient}.
|
* {@link ReactiveElasticsearchClient}.
|
||||||
|
@ -17,14 +17,12 @@ package org.springframework.data.elasticsearch.core;
|
|||||||
|
|
||||||
import static org.elasticsearch.index.VersionType.*;
|
import static org.elasticsearch.index.VersionType.*;
|
||||||
|
|
||||||
import lombok.NonNull;
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.elasticsearch.action.delete.DeleteRequest;
|
import org.elasticsearch.action.delete.DeleteRequest;
|
||||||
import org.elasticsearch.action.get.GetRequest;
|
import org.elasticsearch.action.get.GetRequest;
|
||||||
@ -87,9 +85,10 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
|
|
||||||
private final ReactiveElasticsearchClient client;
|
private final ReactiveElasticsearchClient client;
|
||||||
private final ElasticsearchConverter converter;
|
private final ElasticsearchConverter converter;
|
||||||
private final @NonNull MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
private final ElasticsearchExceptionTranslator exceptionTranslator;
|
private final ElasticsearchExceptionTranslator exceptionTranslator;
|
||||||
private final EntityOperations operations;
|
private final EntityOperations operations;
|
||||||
|
protected RequestFactory requestFactory;
|
||||||
|
|
||||||
private @Nullable RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
|
private @Nullable RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
|
||||||
private @Nullable IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled();
|
private @Nullable IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled();
|
||||||
@ -99,6 +98,8 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client, ElasticsearchConverter converter) {
|
public ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client, ElasticsearchConverter converter) {
|
||||||
|
Assert.notNull(client, "client must not be null");
|
||||||
|
Assert.notNull(converter, "converter must not be null");
|
||||||
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
@ -106,6 +107,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
|
|
||||||
this.exceptionTranslator = new ElasticsearchExceptionTranslator();
|
this.exceptionTranslator = new ElasticsearchExceptionTranslator();
|
||||||
this.operations = new EntityOperations(this.mappingContext);
|
this.operations = new EntityOperations(this.mappingContext);
|
||||||
|
this.requestFactory = new RequestFactory(converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -119,33 +121,30 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#index(Object, String, String)
|
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#index(Object, IndexCoordinates)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> Mono<T> save(T entity, @Nullable String index, @Nullable String type) {
|
public <T> Mono<T> save(T entity, IndexCoordinates index) {
|
||||||
|
|
||||||
Assert.notNull(entity, "Entity must not be null!");
|
Assert.notNull(entity, "Entity must not be null!");
|
||||||
|
|
||||||
AdaptibleEntity<T> adaptableEntity = operations.forEntity(entity, converter.getConversionService());
|
AdaptibleEntity<T> adaptableEntity = operations.forEntity(entity, converter.getConversionService());
|
||||||
|
|
||||||
return doIndex(entity, adaptableEntity, index, type) //
|
return doIndex(entity, adaptableEntity, index) //
|
||||||
.map(it -> {
|
.map(it -> {
|
||||||
return adaptableEntity.populateIdIfNecessary(it.getId());
|
return adaptableEntity.populateIdIfNecessary(it.getId());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<IndexResponse> doIndex(Object value, AdaptibleEntity<?> entity, @Nullable String index,
|
private Mono<IndexResponse> doIndex(Object value, AdaptibleEntity<?> entity, IndexCoordinates index) {
|
||||||
@Nullable String type) {
|
|
||||||
|
|
||||||
return Mono.defer(() -> {
|
return Mono.defer(() -> {
|
||||||
|
|
||||||
Object id = entity.getId();
|
Object id = entity.getId();
|
||||||
|
|
||||||
IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type);
|
|
||||||
|
|
||||||
IndexRequest request = id != null
|
IndexRequest request = id != null
|
||||||
? new IndexRequest(indexCoordinates.getIndexName(), indexCoordinates.getTypeName(), converter.convertId(id))
|
? new IndexRequest(index.getIndexName(), index.getTypeName(), converter.convertId(id))
|
||||||
: new IndexRequest(indexCoordinates.getIndexName(), indexCoordinates.getTypeName());
|
: new IndexRequest(index.getIndexName(), index.getTypeName());
|
||||||
|
|
||||||
request.source(converter.mapObject(value).toJson(), Requests.INDEX_CONTENT_TYPE);
|
request.source(converter.mapObject(value).toJson(), Requests.INDEX_CONTENT_TYPE);
|
||||||
|
|
||||||
@ -165,69 +164,60 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#findById(String, Class, String, String)
|
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#findById(String, Class, IndexCoordinates)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> Mono<T> findById(String id, Class<T> entityType, @Nullable String index, @Nullable String type) {
|
public <T> Mono<T> findById(String id, Class<T> entityType, IndexCoordinates index) {
|
||||||
|
|
||||||
Assert.notNull(id, "Id must not be null!");
|
Assert.notNull(id, "Id must not be null!");
|
||||||
|
|
||||||
return doFindById(id, getPersistentEntity(entityType), index, type)
|
return doFindById(id, getPersistentEntityFor(entityType), index)
|
||||||
.map(it -> converter.mapDocument(DocumentAdapters.from(it), entityType));
|
.map(it -> converter.mapDocument(DocumentAdapters.from(it), entityType));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<GetResult> doFindById(String id, ElasticsearchPersistentEntity<?> entity, @Nullable String index,
|
private Mono<GetResult> doFindById(String id, ElasticsearchPersistentEntity<?> entity, IndexCoordinates index) {
|
||||||
@Nullable String type) {
|
|
||||||
|
|
||||||
return Mono.defer(() -> {
|
return Mono.defer(() -> {
|
||||||
|
|
||||||
IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type);
|
return doFindById(new GetRequest(index.getIndexName(), index.getTypeName(), id));
|
||||||
|
|
||||||
return doFindById(new GetRequest(indexCoordinates.getIndexName(), indexCoordinates.getTypeName(), id));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#exists(String, Class, String, String)
|
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#exists(String, Class, IndexCoordinates)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#exists(String, Class, String, String)
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Mono<Boolean> exists(String id, Class<?> entityType, String index, String type) {
|
public Mono<Boolean> exists(String id, Class<?> entityType, IndexCoordinates index) {
|
||||||
|
|
||||||
Assert.notNull(id, "Id must not be null!");
|
Assert.notNull(id, "Id must not be null!");
|
||||||
|
|
||||||
return doExists(id, getPersistentEntity(entityType), index, type);
|
return doExists(id, getPersistentEntityFor(entityType), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<Boolean> doExists(String id, ElasticsearchPersistentEntity<?> entity, @Nullable String index,
|
private Mono<Boolean> doExists(String id, ElasticsearchPersistentEntity<?> entity, @Nullable IndexCoordinates index) {
|
||||||
@Nullable String type) {
|
|
||||||
|
|
||||||
return Mono.defer(() -> {
|
return Mono.defer(() -> doExists(new GetRequest(index.getIndexName(), index.getTypeName(), id)));
|
||||||
|
|
||||||
IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type);
|
|
||||||
|
|
||||||
return doExists(new GetRequest(indexCoordinates.getIndexName(), indexCoordinates.getTypeName(), id));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#find(Query, Class, String, String, Class)
|
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#find(Query, Class, Class, IndexCoordinates)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> Flux<T> find(Query query, Class<?> entityType, @Nullable String index, @Nullable String type,
|
public <T> Flux<T> find(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) {
|
||||||
Class<T> resultType) {
|
|
||||||
|
|
||||||
return doFind(query, getPersistentEntity(entityType), index, type)
|
return doFind(query, entityType, index).map(it -> converter.mapDocument(DocumentAdapters.from(it), resultType));
|
||||||
.map(it -> converter.mapDocument(DocumentAdapters.from(it), resultType));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Flux<SearchHit> doFind(Query query, ElasticsearchPersistentEntity<?> entity, @Nullable String index,
|
private Flux<SearchHit> doFind(Query query, Class<?> clazz, IndexCoordinates index) {
|
||||||
@Nullable String type) {
|
|
||||||
|
|
||||||
return Flux.defer(() -> {
|
return Flux.defer(() -> {
|
||||||
SearchRequest request = prepareSearchRequest(buildSearchRequest(query, entity, index, type));
|
SearchRequest request = requestFactory.searchRequest(query, clazz, index);
|
||||||
|
|
||||||
|
if (indicesOptions != null) {
|
||||||
|
request.indicesOptions(indicesOptions);
|
||||||
|
}
|
||||||
|
|
||||||
if (query.getPageable().isPaged() || query.isLimiting()) {
|
if (query.getPageable().isPaged() || query.isLimiting()) {
|
||||||
return doFind(request);
|
return doFind(request);
|
||||||
@ -238,26 +228,23 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Long> count(Query query, Class<?> entityType, String index, String type) {
|
public Mono<Long> count(Query query, Class<?> entityType, IndexCoordinates index) {
|
||||||
return doCount(query, getPersistentEntity(entityType), index, type);
|
return doCount(query, getPersistentEntityFor(entityType), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<Long> doCount(Query query, ElasticsearchPersistentEntity<?> entity, @Nullable String index,
|
private Mono<Long> doCount(Query query, ElasticsearchPersistentEntity<?> entity, IndexCoordinates index) {
|
||||||
@Nullable String type) {
|
|
||||||
return Mono.defer(() -> {
|
return Mono.defer(() -> {
|
||||||
|
|
||||||
CountRequest countRequest = buildCountRequest(query, entity, index, type);
|
CountRequest countRequest = buildCountRequest(query, entity, index);
|
||||||
CountRequest request = prepareCountRequest(countRequest);
|
CountRequest request = prepareCountRequest(countRequest);
|
||||||
return doCount(request);
|
return doCount(request);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CountRequest buildCountRequest(Query query, ElasticsearchPersistentEntity<?> entity, @Nullable String index,
|
private CountRequest buildCountRequest(Query query, ElasticsearchPersistentEntity<?> entity, IndexCoordinates index) {
|
||||||
@Nullable String type) {
|
|
||||||
|
|
||||||
IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type);
|
CountRequest request = new CountRequest(index.getIndexNames());
|
||||||
CountRequest request = new CountRequest(indices(query, indexCoordinates::getIndexName));
|
|
||||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||||
searchSourceBuilder.query(mappedQuery(query, entity));
|
searchSourceBuilder.query(mappedQuery(query, entity));
|
||||||
searchSourceBuilder.trackScores(query.getTrackScores());
|
searchSourceBuilder.trackScores(query.getTrackScores());
|
||||||
@ -292,131 +279,60 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchRequest buildSearchRequest(Query query, ElasticsearchPersistentEntity<?> entity, @Nullable String index,
|
|
||||||
@Nullable String type) {
|
|
||||||
IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type);
|
|
||||||
SearchRequest request = new SearchRequest(indices(query, indexCoordinates::getIndexName));
|
|
||||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
||||||
searchSourceBuilder.query(mappedQuery(query, entity));
|
|
||||||
searchSourceBuilder.version(entity.hasVersionProperty());
|
|
||||||
searchSourceBuilder.trackScores(query.getTrackScores());
|
|
||||||
|
|
||||||
QueryBuilder postFilterQuery = mappedFilterQuery(query, entity);
|
|
||||||
if (postFilterQuery != null) {
|
|
||||||
searchSourceBuilder.postFilter(postFilterQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.getSourceFilter() != null) {
|
|
||||||
searchSourceBuilder.fetchSource(query.getSourceFilter().getIncludes(), query.getSourceFilter().getExcludes());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query instanceof NativeSearchQuery && ((NativeSearchQuery) query).getCollapseBuilder() != null) {
|
|
||||||
searchSourceBuilder.collapse(((NativeSearchQuery) query).getCollapseBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
sort(query, entity).forEach(searchSourceBuilder::sort);
|
|
||||||
|
|
||||||
if (query.getMinScore() > 0) {
|
|
||||||
searchSourceBuilder.minScore(query.getMinScore());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.getIndicesOptions() != null) {
|
|
||||||
request.indicesOptions(query.getIndicesOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.getPreference() != null) {
|
|
||||||
request.preference(query.getPreference());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.getSearchType() != null) {
|
|
||||||
request.searchType(query.getSearchType());
|
|
||||||
}
|
|
||||||
|
|
||||||
Pageable pageable = query.getPageable();
|
|
||||||
|
|
||||||
if (pageable.isPaged()) {
|
|
||||||
|
|
||||||
long offset = pageable.getOffset();
|
|
||||||
if (offset > Integer.MAX_VALUE) {
|
|
||||||
throw new IllegalArgumentException(String.format("Offset must not be more than %s", Integer.MAX_VALUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
searchSourceBuilder.from((int) offset);
|
|
||||||
searchSourceBuilder.size(pageable.getPageSize());
|
|
||||||
|
|
||||||
request.source(searchSourceBuilder);
|
|
||||||
request.source(searchSourceBuilder);
|
|
||||||
} else if (query.isLimiting()) {
|
|
||||||
searchSourceBuilder.from(0);
|
|
||||||
searchSourceBuilder.size(query.getMaxResults());
|
|
||||||
|
|
||||||
request.source(searchSourceBuilder);
|
|
||||||
} else {
|
|
||||||
request.source(searchSourceBuilder);
|
|
||||||
}
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#delete(Object, String, String)
|
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#delete(Object, String, String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Mono<String> delete(Object entity, @Nullable String index, @Nullable String type) {
|
public Mono<String> delete(Object entity, IndexCoordinates index) {
|
||||||
|
|
||||||
Entity<?> elasticsearchEntity = operations.forEntity(entity);
|
Entity<?> elasticsearchEntity = operations.forEntity(entity);
|
||||||
|
|
||||||
return Mono.defer(() -> doDeleteById(entity, converter.convertId(elasticsearchEntity.getId()),
|
return Mono.defer(() -> doDeleteById(entity, converter.convertId(elasticsearchEntity.getId()),
|
||||||
elasticsearchEntity.getPersistentEntity(), index, type));
|
elasticsearchEntity.getPersistentEntity(), index));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#delete(String, Class, String, String)
|
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#delete(String, Class, IndexCoordinates)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Mono<String> deleteById(String id, Class<?> entityType, @Nullable String index, @Nullable String type) {
|
public Mono<String> deleteById(String id, Class<?> entityType, IndexCoordinates index) {
|
||||||
|
|
||||||
Assert.notNull(id, "Id must not be null!");
|
Assert.notNull(id, "Id must not be null!");
|
||||||
|
|
||||||
return doDeleteById(null, id, getPersistentEntity(entityType), index, type);
|
return doDeleteById(null, id, getPersistentEntityFor(entityType), index);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<String> doDeleteById(@Nullable Object source, String id, ElasticsearchPersistentEntity<?> entity,
|
private Mono<String> doDeleteById(@Nullable Object source, String id, ElasticsearchPersistentEntity<?> entity,
|
||||||
@Nullable String index, @Nullable String type) {
|
IndexCoordinates index) {
|
||||||
|
|
||||||
return Mono.defer(() -> {
|
return Mono.defer(() -> {
|
||||||
|
|
||||||
IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type);
|
return doDelete(prepareDeleteRequest(source, new DeleteRequest(index.getIndexName(), index.getTypeName(), id)));
|
||||||
|
|
||||||
return doDelete(prepareDeleteRequest(source,
|
|
||||||
new DeleteRequest(indexCoordinates.getIndexName(), indexCoordinates.getTypeName(), id)));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#deleteBy(Query, Class, String, String)
|
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#deleteBy(Query, Class, IndexCoordinates)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Mono<Long> deleteBy(Query query, Class<?> entityType, String index, String type) {
|
public Mono<Long> deleteBy(Query query, Class<?> entityType, IndexCoordinates index) {
|
||||||
|
|
||||||
Assert.notNull(query, "Query must not be null!");
|
Assert.notNull(query, "Query must not be null!");
|
||||||
|
|
||||||
return doDeleteBy(query, getPersistentEntity(entityType), index, type).map(BulkByScrollResponse::getDeleted)
|
return doDeleteBy(query, getPersistentEntityFor(entityType), index).map(BulkByScrollResponse::getDeleted)
|
||||||
.publishNext();
|
.publishNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Flux<BulkByScrollResponse> doDeleteBy(Query query, ElasticsearchPersistentEntity<?> entity,
|
private Flux<BulkByScrollResponse> doDeleteBy(Query query, ElasticsearchPersistentEntity<?> entity,
|
||||||
@Nullable String index, @Nullable String type) {
|
IndexCoordinates index) {
|
||||||
|
|
||||||
return Flux.defer(() -> {
|
return Flux.defer(() -> {
|
||||||
|
DeleteByQueryRequest request = new DeleteByQueryRequest(index.getIndexNames());
|
||||||
IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type);
|
request.types(index.getTypeNames());
|
||||||
|
|
||||||
DeleteByQueryRequest request = new DeleteByQueryRequest(indices(query, indexCoordinates::getIndexName));
|
|
||||||
request.types(indexTypes(query, indexCoordinates::getTypeName));
|
|
||||||
request.setQuery(mappedQuery(query, entity));
|
request.setQuery(mappedQuery(query, entity));
|
||||||
|
|
||||||
return doDeleteBy(prepareDeleteByRequest(request));
|
return doDeleteBy(prepareDeleteByRequest(request));
|
||||||
@ -675,24 +591,6 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
|
|
||||||
// private helpers
|
// private helpers
|
||||||
|
|
||||||
private static String[] indices(Query query, Supplier<String> index) {
|
|
||||||
|
|
||||||
if (query.getIndices().isEmpty()) {
|
|
||||||
return new String[] { index.get() };
|
|
||||||
}
|
|
||||||
|
|
||||||
return query.getIndices().toArray(new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String[] indexTypes(Query query, Supplier<String> indexType) {
|
|
||||||
|
|
||||||
if (query.getTypes().isEmpty()) {
|
|
||||||
return new String[] { indexType.get() };
|
|
||||||
}
|
|
||||||
|
|
||||||
return query.getTypes().toArray(new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<FieldSortBuilder> sort(Query query, ElasticsearchPersistentEntity<?> entity) {
|
private static List<FieldSortBuilder> sort(Query query, ElasticsearchPersistentEntity<?> entity) {
|
||||||
|
|
||||||
if (query.getSort() == null || query.getSort().isUnsorted()) {
|
if (query.getSort() == null || query.getSort().isUnsorted()) {
|
||||||
@ -749,8 +647,9 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
private ElasticsearchPersistentEntity<?> getPersistentEntity(@Nullable Class<?> type) {
|
public ElasticsearchPersistentEntity<?> getPersistentEntityFor(@Nullable Class<?> type) {
|
||||||
return type != null ? mappingContext.getPersistentEntity(type) : null;
|
return type != null ? mappingContext.getPersistentEntity(type) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,17 +604,7 @@ class RequestFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (query instanceof NativeSearchQuery) {
|
if (query instanceof NativeSearchQuery) {
|
||||||
NativeSearchQuery nativeSearchQuery = (NativeSearchQuery) query;
|
prepareNativeSearch((NativeSearchQuery) query, sourceBuilder);
|
||||||
|
|
||||||
if (!nativeSearchQuery.getScriptFields().isEmpty()) {
|
|
||||||
for (ScriptField scriptedField : nativeSearchQuery.getScriptFields()) {
|
|
||||||
sourceBuilder.scriptField(scriptedField.fieldName(), scriptedField.script());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nativeSearchQuery.getCollapseBuilder() != null) {
|
|
||||||
sourceBuilder.collapse(nativeSearchQuery.getCollapseBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,6 +671,33 @@ class RequestFactory {
|
|||||||
return searchRequestBuilder;
|
return searchRequestBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareNativeSearch(NativeSearchQuery query, SearchSourceBuilder sourceBuilder) {
|
||||||
|
NativeSearchQuery nativeSearchQuery = query;
|
||||||
|
|
||||||
|
if (!nativeSearchQuery.getScriptFields().isEmpty()) {
|
||||||
|
for (ScriptField scriptedField : nativeSearchQuery.getScriptFields()) {
|
||||||
|
sourceBuilder.scriptField(scriptedField.fieldName(), scriptedField.script());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nativeSearchQuery.getCollapseBuilder() != null) {
|
||||||
|
sourceBuilder.collapse(nativeSearchQuery.getCollapseBuilder());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isEmpty(nativeSearchQuery.getIndicesBoost())) {
|
||||||
|
for (IndexBoost indexBoost : nativeSearchQuery.getIndicesBoost()) {
|
||||||
|
sourceBuilder.indexBoost(indexBoost.getIndexName(), indexBoost.getBoost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isEmpty(nativeSearchQuery.getAggregations())) {
|
||||||
|
for (AbstractAggregationBuilder aggregationBuilder : nativeSearchQuery.getAggregations()) {
|
||||||
|
sourceBuilder.aggregation(aggregationBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void prepareNativeSearch(SearchRequestBuilder searchRequestBuilder, NativeSearchQuery nativeSearchQuery) {
|
private void prepareNativeSearch(SearchRequestBuilder searchRequestBuilder, NativeSearchQuery nativeSearchQuery) {
|
||||||
if (!isEmpty(nativeSearchQuery.getScriptFields())) {
|
if (!isEmpty(nativeSearchQuery.getScriptFields())) {
|
||||||
for (ScriptField scriptedField : nativeSearchQuery.getScriptFields()) {
|
for (ScriptField scriptedField : nativeSearchQuery.getScriptFields()) {
|
||||||
|
@ -42,8 +42,6 @@ abstract class AbstractQuery implements Query {
|
|||||||
|
|
||||||
protected Pageable pageable = DEFAULT_PAGE;
|
protected Pageable pageable = DEFAULT_PAGE;
|
||||||
protected Sort sort;
|
protected Sort sort;
|
||||||
protected List<String> indices = new ArrayList<>();
|
|
||||||
protected List<String> types = new ArrayList<>();
|
|
||||||
protected List<String> fields = new ArrayList<>();
|
protected List<String> fields = new ArrayList<>();
|
||||||
protected SourceFilter sourceFilter;
|
protected SourceFilter sourceFilter;
|
||||||
protected float minScore;
|
protected float minScore;
|
||||||
@ -84,26 +82,6 @@ abstract class AbstractQuery implements Query {
|
|||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getIndices() {
|
|
||||||
return indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addIndices(String... indices) {
|
|
||||||
addAll(this.indices, indices);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTypes(String... types) {
|
|
||||||
addAll(this.types, types);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getTypes() {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addSourceFilter(SourceFilter sourceFilter) {
|
public void addSourceFilter(SourceFilter sourceFilter) {
|
||||||
this.sourceFilter = sourceFilter;
|
this.sourceFilter = sourceFilter;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
import static java.util.Collections.addAll;
|
import static java.util.Collections.*;
|
||||||
import static org.springframework.data.elasticsearch.core.query.AbstractQuery.*;
|
import static org.springframework.data.elasticsearch.core.query.AbstractQuery.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -28,12 +28,11 @@ import org.springframework.data.domain.Pageable;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
public class MoreLikeThisQuery {
|
public class MoreLikeThisQuery {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String indexName;
|
|
||||||
private String type;
|
|
||||||
private List<String> searchIndices = new ArrayList<>();
|
private List<String> searchIndices = new ArrayList<>();
|
||||||
private List<String> searchTypes = new ArrayList<>();
|
private List<String> searchTypes = new ArrayList<>();
|
||||||
private List<String> fields = new ArrayList<>();
|
private List<String> fields = new ArrayList<>();
|
||||||
@ -57,22 +56,6 @@ public class MoreLikeThisQuery {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIndexName() {
|
|
||||||
return indexName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIndexName(String indexName) {
|
|
||||||
this.indexName = indexName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getSearchIndices() {
|
public List<String> getSearchIndices() {
|
||||||
return searchIndices;
|
return searchIndices;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import org.springframework.data.domain.Pageable;
|
|||||||
* @author Jean-Baptiste Nizet
|
* @author Jean-Baptiste Nizet
|
||||||
* @author Martin Choraine
|
* @author Martin Choraine
|
||||||
* @author Farid Azaza
|
* @author Farid Azaza
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
public class NativeSearchQueryBuilder {
|
public class NativeSearchQueryBuilder {
|
||||||
|
|
||||||
@ -53,8 +54,6 @@ public class NativeSearchQueryBuilder {
|
|||||||
private HighlightBuilder highlightBuilder;
|
private HighlightBuilder highlightBuilder;
|
||||||
private HighlightBuilder.Field[] highlightFields;
|
private HighlightBuilder.Field[] highlightFields;
|
||||||
private Pageable pageable = Pageable.unpaged();
|
private Pageable pageable = Pageable.unpaged();
|
||||||
private String[] indices;
|
|
||||||
private String[] types;
|
|
||||||
private String[] fields;
|
private String[] fields;
|
||||||
private SourceFilter sourceFilter;
|
private SourceFilter sourceFilter;
|
||||||
private CollapseBuilder collapseBuilder;
|
private CollapseBuilder collapseBuilder;
|
||||||
@ -117,16 +116,6 @@ public class NativeSearchQueryBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withIndices(String... indices) {
|
|
||||||
this.indices = indices;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withTypes(String... types) {
|
|
||||||
this.types = types;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NativeSearchQueryBuilder withFields(String... fields) {
|
public NativeSearchQueryBuilder withFields(String... fields) {
|
||||||
this.fields = fields;
|
this.fields = fields;
|
||||||
return this;
|
return this;
|
||||||
@ -184,14 +173,6 @@ public class NativeSearchQueryBuilder {
|
|||||||
nativeSearchQuery.setPageable(pageable);
|
nativeSearchQuery.setPageable(pageable);
|
||||||
nativeSearchQuery.setTrackScores(trackScores);
|
nativeSearchQuery.setTrackScores(trackScores);
|
||||||
|
|
||||||
if (indices != null) {
|
|
||||||
nativeSearchQuery.addIndices(indices);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (types != null) {
|
|
||||||
nativeSearchQuery.addTypes(types);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
nativeSearchQuery.addFields(fields);
|
nativeSearchQuery.addFields(fields);
|
||||||
}
|
}
|
||||||
|
@ -81,38 +81,6 @@ public interface Query {
|
|||||||
*/
|
*/
|
||||||
Sort getSort();
|
Sort getSort();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Indices to be searched
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
List<String> getIndices();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add Indices to be added as part of search request
|
|
||||||
*
|
|
||||||
* @param indices
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
void addIndices(String... indices);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add types to be searched
|
|
||||||
*
|
|
||||||
* @param types
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
void addTypes(String... types);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get types to be searched
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
List<String> getTypes();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add fields to be added as part of search request
|
* Add fields to be added as part of search request
|
||||||
*
|
*
|
||||||
|
@ -20,6 +20,7 @@ import reactor.core.publisher.Mono;
|
|||||||
|
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
@ -36,6 +37,7 @@ import org.springframework.data.repository.query.ResultProcessor;
|
|||||||
* AbstractElasticsearchRepositoryQuery
|
* AbstractElasticsearchRepositoryQuery
|
||||||
*
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
abstract class AbstractReactiveElasticsearchRepositoryQuery implements RepositoryQuery {
|
abstract class AbstractReactiveElasticsearchRepositoryQuery implements RepositoryQuery {
|
||||||
@ -79,14 +81,15 @@ abstract class AbstractReactiveElasticsearchRepositoryQuery implements Repositor
|
|||||||
Query query = createQuery(
|
Query query = createQuery(
|
||||||
new ConvertingParameterAccessor(elasticsearchOperations.getElasticsearchConverter(), parameterAccessor));
|
new ConvertingParameterAccessor(elasticsearchOperations.getElasticsearchConverter(), parameterAccessor));
|
||||||
|
|
||||||
Class<?> typeToRead = processor.getReturnedType().getTypeToRead();
|
Class<?> targetType = processor.getReturnedType().getTypeToRead();
|
||||||
String indexName = queryMethod.getEntityInformation().getIndexName();
|
String indexName = queryMethod.getEntityInformation().getIndexName();
|
||||||
String indexTypeName = queryMethod.getEntityInformation().getIndexTypeName();
|
String indexTypeName = queryMethod.getEntityInformation().getIndexTypeName();
|
||||||
|
IndexCoordinates index = IndexCoordinates.of(indexName).withTypes(indexTypeName);
|
||||||
|
|
||||||
ReactiveElasticsearchQueryExecution execution = getExecution(parameterAccessor,
|
ReactiveElasticsearchQueryExecution execution = getExecution(parameterAccessor,
|
||||||
new ResultProcessingConverter(processor, elasticsearchOperations));
|
new ResultProcessingConverter(processor, elasticsearchOperations));
|
||||||
|
|
||||||
return execution.execute(query, processor.getReturnedType().getDomainType(), indexName, indexTypeName, typeToRead);
|
return execution.execute(query, processor.getReturnedType().getDomainType(), targetType, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReactiveElasticsearchQueryExecution getExecution(ElasticsearchParameterAccessor accessor,
|
private ReactiveElasticsearchQueryExecution getExecution(ElasticsearchParameterAccessor accessor,
|
||||||
@ -106,15 +109,17 @@ abstract class AbstractReactiveElasticsearchRepositoryQuery implements Repositor
|
|||||||
ReactiveElasticsearchOperations operations) {
|
ReactiveElasticsearchOperations operations) {
|
||||||
|
|
||||||
if (isDeleteQuery()) {
|
if (isDeleteQuery()) {
|
||||||
return (q, t, i, it, tt) -> operations.deleteBy(q, t, i, it);
|
return (query, type, targetType, indexCoordinates) -> operations.deleteBy(query, type, indexCoordinates);
|
||||||
} else if (isCountQuery()) {
|
} else if (isCountQuery()) {
|
||||||
return (q, t, i, it, tt) -> operations.count(q, t, i, it);
|
return (query, type, targetType, indexCoordinates) -> operations.count(query, type, indexCoordinates);
|
||||||
} else if (isExistsQuery()) {
|
} else if (isExistsQuery()) {
|
||||||
return (q, t, i, it, tt) -> operations.count(q, t, i, it).map(count -> count > 0);
|
return (query, type, targetType, indexCoordinates) -> operations.count(query, type, indexCoordinates)
|
||||||
|
.map(count -> count > 0);
|
||||||
} else if (queryMethod.isCollectionQuery()) {
|
} else if (queryMethod.isCollectionQuery()) {
|
||||||
return (q, t, i, it, tt) -> operations.find(q.setPageable(accessor.getPageable()), t, i, it, tt);
|
return (query, type, targetType, indexCoordinates) -> operations.find(query.setPageable(accessor.getPageable()),
|
||||||
|
type, targetType, indexCoordinates);
|
||||||
} else {
|
} else {
|
||||||
return (q, t, i, it, tt) -> operations.find(q, t, i, it, tt);
|
return (query, type, targetType, indexCoordinates) -> operations.find(query, type, targetType, indexCoordinates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,39 +15,46 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.repository.query;
|
package org.springframework.data.elasticsearch.repository.query;
|
||||||
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.repository.query.ResultProcessor;
|
import org.springframework.data.repository.query.ResultProcessor;
|
||||||
import org.springframework.data.repository.query.ReturnedType;
|
import org.springframework.data.repository.query.ReturnedType;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public interface ReactiveElasticsearchQueryExecution {
|
public interface ReactiveElasticsearchQueryExecution {
|
||||||
|
|
||||||
Object execute(Query query, Class<?> type, String indexName, String indexType, @Nullable Class<?> targetType);
|
Object execute(Query query, Class<?> type, @Nullable Class<?> targetType, IndexCoordinates indexCoordinates);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link ReactiveElasticsearchQueryExecution} that wraps the results of the given delegate with the given result
|
* An {@link ReactiveElasticsearchQueryExecution} that wraps the results of the given delegate with the given result
|
||||||
* processing.
|
* processing.
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
|
||||||
final class ResultProcessingExecution implements ReactiveElasticsearchQueryExecution {
|
final class ResultProcessingExecution implements ReactiveElasticsearchQueryExecution {
|
||||||
|
|
||||||
private final @NonNull ReactiveElasticsearchQueryExecution delegate;
|
private final ReactiveElasticsearchQueryExecution delegate;
|
||||||
private final @NonNull Converter<Object, Object> converter;
|
private final Converter<Object, Object> converter;
|
||||||
|
|
||||||
|
public ResultProcessingExecution(ReactiveElasticsearchQueryExecution delegate,
|
||||||
|
Converter<Object, Object> converter) {
|
||||||
|
Assert.notNull(delegate, "delegate must not be null");
|
||||||
|
Assert.notNull(converter, "converter must not be null");
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.converter = converter;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object execute(Query query, Class<?> type, String indexName, String indexType,
|
public Object execute(Query query, Class<?> type, @Nullable Class<?> targetType,
|
||||||
@Nullable Class<?> targetType) {
|
IndexCoordinates indexCoordinates) {
|
||||||
return converter.convert(delegate.execute(query, type, indexName, indexType, targetType));
|
return converter.convert(delegate.execute(query, type, targetType, indexCoordinates));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,11 +63,17 @@ public interface ReactiveElasticsearchQueryExecution {
|
|||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
|
||||||
final class ResultProcessingConverter implements Converter<Object, Object> {
|
final class ResultProcessingConverter implements Converter<Object, Object> {
|
||||||
|
|
||||||
private final @NonNull ResultProcessor processor;
|
private final ResultProcessor processor;
|
||||||
private final @NonNull ReactiveElasticsearchOperations operations;
|
private final ReactiveElasticsearchOperations operations;
|
||||||
|
|
||||||
|
public ResultProcessingConverter(ResultProcessor processor, ReactiveElasticsearchOperations operations) {
|
||||||
|
Assert.notNull(processor, "processor must not be null");
|
||||||
|
Assert.notNull(operations, "operations must not be null");
|
||||||
|
this.processor = processor;
|
||||||
|
this.operations = operations;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
@ -20,6 +20,7 @@ import reactor.core.publisher.Mono;
|
|||||||
|
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
||||||
@ -27,12 +28,14 @@ import org.springframework.util.Assert;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveElasticsearchRepository<T, ID> {
|
public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveElasticsearchRepository<T, ID> {
|
||||||
|
|
||||||
private final ElasticsearchEntityInformation<T, ID> entityInformation;
|
private final ElasticsearchEntityInformation<T, ID> entityInformation;
|
||||||
private final ReactiveElasticsearchOperations elasticsearchOperations;
|
private final ReactiveElasticsearchOperations elasticsearchOperations;
|
||||||
|
private final IndexCoordinates index;
|
||||||
|
|
||||||
public SimpleReactiveElasticsearchRepository(ElasticsearchEntityInformation<T, ID> entityInformation,
|
public SimpleReactiveElasticsearchRepository(ElasticsearchEntityInformation<T, ID> entityInformation,
|
||||||
ReactiveElasticsearchOperations elasticsearchOperations) {
|
ReactiveElasticsearchOperations elasticsearchOperations) {
|
||||||
@ -42,20 +45,20 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
|||||||
|
|
||||||
this.entityInformation = entityInformation;
|
this.entityInformation = entityInformation;
|
||||||
this.elasticsearchOperations = elasticsearchOperations;
|
this.elasticsearchOperations = elasticsearchOperations;
|
||||||
|
this.index = IndexCoordinates.of(entityInformation.getIndexName()).withTypes(entityInformation.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<T> findAll(Sort sort) {
|
public Flux<T> findAll(Sort sort) {
|
||||||
|
|
||||||
return elasticsearchOperations.find(Query.findAll().addSort(sort), entityInformation.getJavaType(),
|
return elasticsearchOperations.find(Query.findAll().addSort(sort), entityInformation.getJavaType(), index);
|
||||||
entityInformation.getIndexName(), entityInformation.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S extends T> Mono<S> save(S entity) {
|
public <S extends T> Mono<S> save(S entity) {
|
||||||
|
|
||||||
Assert.notNull(entity, "Entity must not be null!");
|
Assert.notNull(entity, "Entity must not be null!");
|
||||||
return elasticsearchOperations.save(entity, entityInformation.getIndexName(), entityInformation.getType());
|
return elasticsearchOperations.save(entity, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -76,8 +79,7 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
|||||||
public Mono<T> findById(ID id) {
|
public Mono<T> findById(ID id) {
|
||||||
|
|
||||||
Assert.notNull(id, "Id must not be null!");
|
Assert.notNull(id, "Id must not be null!");
|
||||||
return elasticsearchOperations.findById(convertId(id), entityInformation.getJavaType(),
|
return elasticsearchOperations.findById(convertId(id), entityInformation.getJavaType(), index);
|
||||||
entityInformation.getIndexName(), entityInformation.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,8 +93,7 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
|||||||
public Mono<Boolean> existsById(ID id) {
|
public Mono<Boolean> existsById(ID id) {
|
||||||
|
|
||||||
Assert.notNull(id, "Id must not be null!");
|
Assert.notNull(id, "Id must not be null!");
|
||||||
return elasticsearchOperations.exists(convertId(id), entityInformation.getJavaType(),
|
return elasticsearchOperations.exists(convertId(id), entityInformation.getJavaType(), index);
|
||||||
entityInformation.getIndexName(), entityInformation.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,8 +106,7 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
|||||||
@Override
|
@Override
|
||||||
public Flux<T> findAll() {
|
public Flux<T> findAll() {
|
||||||
|
|
||||||
return elasticsearchOperations.find(Query.findAll(), entityInformation.getJavaType(),
|
return elasticsearchOperations.find(Query.findAll(), entityInformation.getJavaType(), index);
|
||||||
entityInformation.getIndexName(), entityInformation.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -127,17 +127,14 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
|||||||
@Override
|
@Override
|
||||||
public Mono<Long> count() {
|
public Mono<Long> count() {
|
||||||
|
|
||||||
return elasticsearchOperations.count(Query.findAll(), entityInformation.getJavaType(),
|
return elasticsearchOperations.count(Query.findAll(), entityInformation.getJavaType(), index);
|
||||||
entityInformation.getIndexName(), entityInformation.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> deleteById(ID id) {
|
public Mono<Void> deleteById(ID id) {
|
||||||
|
|
||||||
Assert.notNull(id, "Id must not be null!");
|
Assert.notNull(id, "Id must not be null!");
|
||||||
return elasticsearchOperations
|
return elasticsearchOperations.deleteById(convertId(id), entityInformation.getJavaType(), index) //
|
||||||
.deleteById(convertId(id), entityInformation.getJavaType(), entityInformation.getIndexName(),
|
|
||||||
entityInformation.getType()) //
|
|
||||||
.then();
|
.then();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +149,7 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
|||||||
public Mono<Void> delete(T entity) {
|
public Mono<Void> delete(T entity) {
|
||||||
|
|
||||||
Assert.notNull(entity, "Entity must not be null!");
|
Assert.notNull(entity, "Entity must not be null!");
|
||||||
return elasticsearchOperations.delete(entity, entityInformation.getIndexName(), entityInformation.getType()) //
|
return elasticsearchOperations.delete(entity, index) //
|
||||||
.then();
|
.then();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,9 +170,7 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
|||||||
@Override
|
@Override
|
||||||
public Mono<Void> deleteAll() {
|
public Mono<Void> deleteAll() {
|
||||||
|
|
||||||
return elasticsearchOperations
|
return elasticsearchOperations.deleteBy(Query.findAll(), entityInformation.getJavaType(), index) //
|
||||||
.deleteBy(Query.findAll(), entityInformation.getJavaType(), entityInformation.getIndexName(),
|
|
||||||
entityInformation.getType()) //
|
|
||||||
.then();
|
.then();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME).withIndicesOptions(IndicesOptions.lenientExpandOpen()).build();
|
.withIndicesOptions(IndicesOptions.lenientExpandOpen()).build();
|
||||||
Page<SampleEntity> entities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class,
|
Page<SampleEntity> entities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class,
|
||||||
IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
||||||
|
|
||||||
@ -512,9 +512,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "foo"))
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "foo")).build();
|
||||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME) //
|
|
||||||
.build();
|
|
||||||
|
|
||||||
assertThat(elasticsearchTemplate.count(searchQuery, IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME))).isEqualTo(0);
|
assertThat(elasticsearchTemplate.count(searchQuery, IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME))).isEqualTo(0);
|
||||||
}
|
}
|
||||||
@ -548,9 +546,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "positive"))
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "positive")).build();
|
||||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME) //
|
|
||||||
.build();
|
|
||||||
|
|
||||||
assertThat(elasticsearchTemplate.count(searchQuery, IndexCoordinates.of("test-index-*"))).isEqualTo(2);
|
assertThat(elasticsearchTemplate.count(searchQuery, IndexCoordinates.of("test-index-*"))).isEqualTo(2);
|
||||||
}
|
}
|
||||||
@ -953,8 +949,8 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
elasticsearchTemplate.index(indexQuery, index);
|
elasticsearchTemplate.index(indexQuery, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withFields("message")
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withFields("message").build();
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
||||||
@ -986,7 +982,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
sourceFilter.withIncludes("message");
|
sourceFilter.withIncludes("message");
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withSourceFilter(sourceFilter.build()).build();
|
.withSourceFilter(sourceFilter.build()).build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
||||||
@ -1049,8 +1045,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_NAME_SAMPLE_ENTITY);
|
|
||||||
criteriaQuery.addTypes(TYPE_NAME);
|
|
||||||
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class,
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class,
|
||||||
@ -1077,7 +1071,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
// then
|
// then
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withPageable(PageRequest.of(0, 10)).build();
|
.withPageable(PageRequest.of(0, 10)).build();
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
||||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||||
@ -1101,8 +1095,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_NAME_SAMPLE_ENTITY);
|
|
||||||
criteriaQuery.addTypes(TYPE_NAME);
|
|
||||||
criteriaQuery.addFields("message");
|
criteriaQuery.addFields("message");
|
||||||
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
||||||
|
|
||||||
@ -1130,9 +1122,8 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withFields("message")
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withFields("message").withQuery(matchAllQuery())
|
.withQuery(matchAllQuery()).withPageable(PageRequest.of(0, 10)).build();
|
||||||
.withPageable(PageRequest.of(0, 10)).build();
|
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
||||||
String scrollId = scroll.getScrollId();
|
String scrollId = scroll.getScrollId();
|
||||||
@ -1158,8 +1149,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_NAME_SAMPLE_ENTITY);
|
|
||||||
criteriaQuery.addTypes(TYPE_NAME);
|
|
||||||
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class,
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class,
|
||||||
@ -1187,7 +1176,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withPageable(PageRequest.of(0, 10)).build();
|
.withPageable(PageRequest.of(0, 10)).build();
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
||||||
String scrollId = scroll.getScrollId();
|
String scrollId = scroll.getScrollId();
|
||||||
@ -1266,8 +1255,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_NAME_SAMPLE_ENTITY);
|
|
||||||
criteriaQuery.addTypes(TYPE_NAME);
|
|
||||||
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
||||||
|
|
||||||
CloseableIterator<SampleEntity> stream = elasticsearchTemplate.stream(criteriaQuery, SampleEntity.class, index);
|
CloseableIterator<SampleEntity> stream = elasticsearchTemplate.stream(criteriaQuery, SampleEntity.class, index);
|
||||||
@ -1456,8 +1443,8 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
.withUpdateRequest(updateRequest).build();
|
.withUpdateRequest(updateRequest).build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
UpdateRequest request = elasticsearchTemplate.getRequestFactory().updateRequest(updateQuery,
|
UpdateRequest request = ((AbstractElasticsearchTemplate) elasticsearchTemplate).getRequestFactory()
|
||||||
IndexCoordinates.of("index"));
|
.updateRequest(updateQuery, IndexCoordinates.of("index"));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(request).isNotNull();
|
assertThat(request).isNotNull();
|
||||||
@ -1478,8 +1465,8 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
.withUpdateRequest(updateRequest).build();
|
.withUpdateRequest(updateRequest).build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
UpdateRequest request = elasticsearchTemplate.getRequestFactory().updateRequest(updateQuery,
|
UpdateRequest request = ((AbstractElasticsearchTemplate) elasticsearchTemplate).getRequestFactory()
|
||||||
IndexCoordinates.of("index"));
|
.updateRequest(updateQuery, IndexCoordinates.of("index"));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(request).isNotNull();
|
assertThat(request).isNotNull();
|
||||||
@ -1524,7 +1511,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME).withIndicesOptions(IndicesOptions.lenientExpandOpen()).build();
|
.withIndicesOptions(IndicesOptions.lenientExpandOpen()).build();
|
||||||
|
|
||||||
List<SampleEntity> entities = new ArrayList<>();
|
List<SampleEntity> entities = new ArrayList<>();
|
||||||
|
|
||||||
@ -1643,7 +1630,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.index(indexQuery, IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME));
|
elasticsearchTemplate.index(indexQuery, IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME));
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", indexQuery.getId()))
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", indexQuery.getId()))
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).build();
|
.build();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
||||||
@ -1672,7 +1659,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.bulkIndex(entities, index);
|
elasticsearchTemplate.bulkIndex(entities, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "message"))
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "message"))
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withPageable(PageRequest.of(0, 100)).build();
|
.withPageable(PageRequest.of(0, 100)).build();
|
||||||
// then
|
// then
|
||||||
List<String> ids = elasticsearchTemplate.queryForIds(searchQuery, SampleEntity.class, index);
|
List<String> ids = elasticsearchTemplate.queryForIds(searchQuery, SampleEntity.class, index);
|
||||||
assertThat(ids).hasSize(30);
|
assertThat(ids).hasSize(30);
|
||||||
@ -1693,7 +1680,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
// when
|
// when
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
.withQuery(boolQuery().must(wildcardQuery("message", "*a*")).should(wildcardQuery("message", "*b*")))
|
.withQuery(boolQuery().must(wildcardQuery("message", "*a*")).should(wildcardQuery("message", "*b*")))
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withMinScore(2.0F).build();
|
.withMinScore(2.0F).build();
|
||||||
|
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
@ -1823,8 +1810,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(index);
|
elasticsearchTemplate.refresh(index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withIndices(INDEX_NAME_SAMPLE_ENTITY)
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withTypes(TYPE_NAME).withQuery(matchAllQuery()).build();
|
|
||||||
Page<Map> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, Map.class, index);
|
Page<Map> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, Map.class, index);
|
||||||
|
|
||||||
assertThat(sampleEntities.getTotalElements()).isEqualTo(2);
|
assertThat(sampleEntities.getTotalElements()).isEqualTo(2);
|
||||||
@ -1847,8 +1833,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.index(indexQueryBuilder.build(), index);
|
elasticsearchTemplate.index(indexQueryBuilder.build(), index);
|
||||||
elasticsearchTemplate.refresh(index);
|
elasticsearchTemplate.refresh(index);
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withIndices(INDEX_NAME_SAMPLE_ENTITY)
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withTypes(TYPE_NAME).withQuery(matchAllQuery()).build();
|
|
||||||
// when
|
// when
|
||||||
Page<GTEVersionEntity> entities = elasticsearchTemplate.queryForPage(searchQuery, GTEVersionEntity.class, index);
|
Page<GTEVersionEntity> entities = elasticsearchTemplate.queryForPage(searchQuery, GTEVersionEntity.class, index);
|
||||||
// then
|
// then
|
||||||
@ -1878,8 +1863,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.index(indexQuery, IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME));
|
elasticsearchTemplate.index(indexQuery, IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME));
|
||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_NAME_SAMPLE_ENTITY));
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withIndices(INDEX_NAME_SAMPLE_ENTITY)
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withTypes(TYPE_NAME).withQuery(matchAllQuery()).build();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
||||||
@ -1901,7 +1885,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.index(indexQuery, index);
|
elasticsearchTemplate.index(indexQuery, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_NAME_SAMPLE_ENTITY);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
long count = elasticsearchTemplate.count(criteriaQuery, SampleEntity.class, index);
|
long count = elasticsearchTemplate.count(criteriaQuery, SampleEntity.class, index);
|
||||||
@ -1921,8 +1904,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
||||||
elasticsearchTemplate.index(indexQuery, index);
|
elasticsearchTemplate.index(indexQuery, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).build();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
long count = elasticsearchTemplate.count(searchQuery, SampleEntity.class, index);
|
long count = elasticsearchTemplate.count(searchQuery, SampleEntity.class, index);
|
||||||
@ -1943,12 +1925,10 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.index(indexQuery, index);
|
elasticsearchTemplate.index(indexQuery, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_NAME_SAMPLE_ENTITY);
|
|
||||||
criteriaQuery.addTypes(TYPE_NAME);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
|
||||||
long count = elasticsearchTemplate.count(criteriaQuery, index);
|
long count = elasticsearchTemplate.count(criteriaQuery, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(count).isEqualTo(1);
|
assertThat(count).isEqualTo(1);
|
||||||
}
|
}
|
||||||
@ -1964,8 +1944,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
||||||
elasticsearchTemplate.index(indexQuery, index);
|
elasticsearchTemplate.index(indexQuery, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).build();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
long count = elasticsearchTemplate.count(searchQuery, index);
|
long count = elasticsearchTemplate.count(searchQuery, index);
|
||||||
@ -1997,7 +1976,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_1_NAME, INDEX_2_NAME);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
long count = elasticsearchTemplate.count(criteriaQuery, IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
long count = elasticsearchTemplate.count(criteriaQuery, IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
||||||
@ -2028,8 +2006,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_1_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_1_NAME));
|
||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME).build();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
long count = elasticsearchTemplate.count(searchQuery, IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
long count = elasticsearchTemplate.count(searchQuery, IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
||||||
@ -2096,7 +2073,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||||
criteriaQuery.addIndices(INDEX_1_NAME);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
long count = elasticsearchTemplate.count(criteriaQuery, IndexCoordinates.of(INDEX_1_NAME));
|
long count = elasticsearchTemplate.count(criteriaQuery, IndexCoordinates.of(INDEX_1_NAME));
|
||||||
@ -2127,8 +2103,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_1_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_1_NAME));
|
||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withIndices(INDEX_1_NAME)
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.build();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
long count = elasticsearchTemplate.count(searchQuery, IndexCoordinates.of(INDEX_1_NAME));
|
long count = elasticsearchTemplate.count(searchQuery, IndexCoordinates.of(INDEX_1_NAME));
|
||||||
@ -2264,8 +2239,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_1_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_1_NAME));
|
||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME).build();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<SampleEntity> sampleEntities = elasticsearchTemplate.queryForList(searchQuery, SampleEntity.class,
|
List<SampleEntity> sampleEntities = elasticsearchTemplate.queryForList(searchQuery, SampleEntity.class,
|
||||||
@ -2294,8 +2268,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
elasticsearchTemplate.refresh(IndexCoordinates.of(INDEX_2_NAME));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTypes("hetro")
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||||
.withIndices(INDEX_1_NAME, INDEX_2_NAME).build();
|
|
||||||
Page<ResultAggregator> page = elasticsearchTemplate.queryForPage(searchQuery, ResultAggregator.class,
|
Page<ResultAggregator> page = elasticsearchTemplate.queryForPage(searchQuery, ResultAggregator.class,
|
||||||
IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
IndexCoordinates.of(INDEX_1_NAME, INDEX_2_NAME));
|
||||||
|
|
||||||
@ -2444,8 +2417,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("message"));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("message"));
|
||||||
criteriaQuery.addIndices(INDEX_NAME_SAMPLE_ENTITY);
|
|
||||||
criteriaQuery.addTypes(TYPE_NAME);
|
|
||||||
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
criteriaQuery.setPageable(PageRequest.of(0, 10));
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class,
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class,
|
||||||
@ -2482,7 +2453,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("message", "message"))
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("message", "message"))
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withPageable(PageRequest.of(0, 10)).build();
|
.withPageable(PageRequest.of(0, 10)).build();
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
||||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||||
@ -2512,8 +2483,7 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
SourceFilter sourceFilter = new FetchSourceFilter(new String[] { "id" }, new String[] {});
|
SourceFilter sourceFilter = new FetchSourceFilter(new String[] { "id" }, new String[] {});
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withPageable(PageRequest.of(0, 10))
|
.withPageable(PageRequest.of(0, 10)).withSourceFilter(sourceFilter).build();
|
||||||
.withSourceFilter(sourceFilter).build();
|
|
||||||
|
|
||||||
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, index);
|
||||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||||
@ -2638,8 +2608,8 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withCollapseField("rate")
|
||||||
.withIndices(INDEX_NAME_SAMPLE_ENTITY).withTypes(TYPE_NAME).withCollapseField("rate").build();
|
.build();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, index);
|
||||||
@ -2770,8 +2740,6 @@ public abstract class ElasticsearchTemplateTests {
|
|||||||
|
|
||||||
NativeSearchQuery query = new NativeSearchQueryBuilder() //
|
NativeSearchQuery query = new NativeSearchQueryBuilder() //
|
||||||
.withQuery(matchAllQuery()) //
|
.withQuery(matchAllQuery()) //
|
||||||
.withIndices(alias) //
|
|
||||||
.withTypes(TYPE_NAME) //
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
long count = elasticsearchTemplate.count(query, IndexCoordinates.of(alias));
|
long count = elasticsearchTemplate.count(query, IndexCoordinates.of(alias));
|
||||||
|
@ -163,14 +163,15 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
public void insertWithExplicitIndexNameShouldOverwriteMetadata() {
|
public void insertWithExplicitIndexNameShouldOverwriteMetadata() {
|
||||||
|
|
||||||
SampleEntity sampleEntity = randomEntity("in another index");
|
SampleEntity sampleEntity = randomEntity("in another index");
|
||||||
|
IndexCoordinates alternateIndex = IndexCoordinates.of(ALTERNATE_INDEX);
|
||||||
|
|
||||||
template.save(sampleEntity, ALTERNATE_INDEX) //
|
template.save(sampleEntity, alternateIndex) //
|
||||||
.as(StepVerifier::create)//
|
.as(StepVerifier::create)//
|
||||||
.expectNextCount(1)//
|
.expectNextCount(1)//
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
restTemplate.refresh(IndexCoordinates.of(DEFAULT_INDEX));
|
restTemplate.refresh(IndexCoordinates.of(DEFAULT_INDEX));
|
||||||
restTemplate.refresh(IndexCoordinates.of(ALTERNATE_INDEX));
|
restTemplate.refresh(alternateIndex);
|
||||||
|
|
||||||
assertThat(TestUtils.documentWithId(sampleEntity.getId()).existsIn(DEFAULT_INDEX)).isFalse();
|
assertThat(TestUtils.documentWithId(sampleEntity.getId()).existsIn(DEFAULT_INDEX)).isFalse();
|
||||||
assertThat(TestUtils.documentWithId(sampleEntity.getId()).existsIn(ALTERNATE_INDEX)).isTrue();
|
assertThat(TestUtils.documentWithId(sampleEntity.getId()).existsIn(ALTERNATE_INDEX)).isTrue();
|
||||||
@ -181,7 +182,7 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
|
|
||||||
Map<String, Object> map = new LinkedHashMap<>(Collections.singletonMap("foo", "bar"));
|
Map<String, Object> map = new LinkedHashMap<>(Collections.singletonMap("foo", "bar"));
|
||||||
|
|
||||||
template.save(map, ALTERNATE_INDEX, "singleton-map") //
|
template.save(map, IndexCoordinates.of(ALTERNATE_INDEX).withTypes("singleton-map")) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.consumeNextWith(actual -> {
|
.consumeNextWith(actual -> {
|
||||||
assertThat(map).containsKey("id");
|
assertThat(map).containsKey("id");
|
||||||
@ -198,7 +199,7 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
@Test // DATAES-519
|
@Test // DATAES-519
|
||||||
public void findByIdShouldCompleteWhenIndexDoesNotExist() {
|
public void findByIdShouldCompleteWhenIndexDoesNotExist() {
|
||||||
|
|
||||||
template.findById("foo", SampleEntity.class, "no-such-index") //
|
template.findById("foo", SampleEntity.class, IndexCoordinates.of("no-such-index").withTypes("test-type")) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
@ -256,17 +257,20 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
|
|
||||||
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
||||||
|
|
||||||
restTemplate.index(indexQuery, IndexCoordinates.of(ALTERNATE_INDEX).withTypes( "test-type"));
|
IndexCoordinates defaultIndex = IndexCoordinates.of(DEFAULT_INDEX).withTypes("test-type");
|
||||||
|
IndexCoordinates alternateIndex = IndexCoordinates.of(ALTERNATE_INDEX).withTypes("test-type");
|
||||||
|
|
||||||
|
restTemplate.index(indexQuery, alternateIndex);
|
||||||
restTemplate.refresh(SampleEntity.class);
|
restTemplate.refresh(SampleEntity.class);
|
||||||
|
|
||||||
restTemplate.refresh(IndexCoordinates.of(DEFAULT_INDEX));
|
restTemplate.refresh(defaultIndex);
|
||||||
restTemplate.refresh(IndexCoordinates.of(ALTERNATE_INDEX));
|
restTemplate.refresh(alternateIndex);
|
||||||
|
|
||||||
template.findById(sampleEntity.getId(), SampleEntity.class) //
|
template.findById(sampleEntity.getId(), SampleEntity.class, defaultIndex) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
template.findById(sampleEntity.getId(), SampleEntity.class, ALTERNATE_INDEX) //
|
template.findById(sampleEntity.getId(), SampleEntity.class, alternateIndex) //
|
||||||
.as(StepVerifier::create)//
|
.as(StepVerifier::create)//
|
||||||
.expectNextCount(1) //
|
.expectNextCount(1) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
@ -275,7 +279,7 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
@Test // DATAES-519
|
@Test // DATAES-519
|
||||||
public void existsShouldReturnFalseWhenIndexDoesNotExist() {
|
public void existsShouldReturnFalseWhenIndexDoesNotExist() {
|
||||||
|
|
||||||
template.exists("foo", SampleEntity.class, "no-such-index") //
|
template.exists("foo", SampleEntity.class, IndexCoordinates.of("no-such-index")) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.expectNext(false) //
|
.expectNext(false) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
@ -308,7 +312,9 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
@Test // DATAES-519
|
@Test // DATAES-519
|
||||||
public void findShouldCompleteWhenIndexDoesNotExist() {
|
public void findShouldCompleteWhenIndexDoesNotExist() {
|
||||||
|
|
||||||
template.find(new CriteriaQuery(Criteria.where("message").is("some message")), SampleEntity.class, "no-such-index") //
|
template
|
||||||
|
.find(new CriteriaQuery(Criteria.where("message").is("some message")), SampleEntity.class,
|
||||||
|
IndexCoordinates.of("no-such-index")) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
@ -509,7 +515,7 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
@Test // DATAES-519
|
@Test // DATAES-519
|
||||||
public void deleteByIdShouldCompleteWhenIndexDoesNotExist() {
|
public void deleteByIdShouldCompleteWhenIndexDoesNotExist() {
|
||||||
|
|
||||||
template.deleteById("does-not-exists", SampleEntity.class, "no-such-index") //
|
template.deleteById("does-not-exists", SampleEntity.class, IndexCoordinates.of("no-such-index")) //
|
||||||
.as(StepVerifier::create)//
|
.as(StepVerifier::create)//
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
@ -532,7 +538,7 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
SampleEntity sampleEntity = randomEntity("test message");
|
SampleEntity sampleEntity = randomEntity("test message");
|
||||||
index(sampleEntity);
|
index(sampleEntity);
|
||||||
|
|
||||||
template.deleteById(sampleEntity.getId(), DEFAULT_INDEX, "test-type") //
|
template.deleteById(sampleEntity.getId(), IndexCoordinates.of(DEFAULT_INDEX).withTypes("test-type")) //
|
||||||
.as(StepVerifier::create)//
|
.as(StepVerifier::create)//
|
||||||
.expectNext(sampleEntity.getId()) //
|
.expectNext(sampleEntity.getId()) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
@ -577,8 +583,8 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
public void shouldDeleteAcrossIndex() {
|
public void shouldDeleteAcrossIndex() {
|
||||||
|
|
||||||
String indexPrefix = "rx-template-test-index";
|
String indexPrefix = "rx-template-test-index";
|
||||||
String thisIndex = indexPrefix + "-this";
|
IndexCoordinates thisIndex = IndexCoordinates.of(indexPrefix + "-this");
|
||||||
String thatIndex = indexPrefix + "-that";
|
IndexCoordinates thatIndex = IndexCoordinates.of(indexPrefix + "-that");
|
||||||
|
|
||||||
template.save(randomEntity("test"), thisIndex) //
|
template.save(randomEntity("test"), thisIndex) //
|
||||||
.then(template.save(randomEntity("test"), thatIndex)) //
|
.then(template.save(randomEntity("test"), thatIndex)) //
|
||||||
@ -586,20 +592,19 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
.as(StepVerifier::create)//
|
.as(StepVerifier::create)//
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
restTemplate.refresh(IndexCoordinates.of(thisIndex));
|
restTemplate.refresh(thisIndex);
|
||||||
restTemplate.refresh(IndexCoordinates.of(thatIndex));
|
restTemplate.refresh(thatIndex);
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() //
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() //
|
||||||
.withQuery(termQuery("message", "test")) //
|
.withQuery(termQuery("message", "test")) //
|
||||||
.withIndices(indexPrefix + "*") //
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
template.deleteBy(searchQuery, SampleEntity.class) //
|
template.deleteBy(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.expectNext(2L) //
|
.expectNext(2L) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
TestUtils.deleteIndex(thisIndex, thatIndex);
|
TestUtils.deleteIndex(thisIndex.getIndexName(), thatIndex.getIndexName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-547
|
@Test // DATAES-547
|
||||||
@ -607,8 +612,8 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
public void shouldDeleteAcrossIndexWhenNoMatchingDataPresent() {
|
public void shouldDeleteAcrossIndexWhenNoMatchingDataPresent() {
|
||||||
|
|
||||||
String indexPrefix = "rx-template-test-index";
|
String indexPrefix = "rx-template-test-index";
|
||||||
String thisIndex = indexPrefix + "-this";
|
IndexCoordinates thisIndex = IndexCoordinates.of(indexPrefix + "-this");
|
||||||
String thatIndex = indexPrefix + "-that";
|
IndexCoordinates thatIndex = IndexCoordinates.of(indexPrefix + "-that");
|
||||||
|
|
||||||
template.save(randomEntity("positive"), thisIndex) //
|
template.save(randomEntity("positive"), thisIndex) //
|
||||||
.then(template.save(randomEntity("positive"), thatIndex)) //
|
.then(template.save(randomEntity("positive"), thatIndex)) //
|
||||||
@ -616,20 +621,19 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
.as(StepVerifier::create)//
|
.as(StepVerifier::create)//
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
restTemplate.refresh(IndexCoordinates.of(thisIndex));
|
restTemplate.refresh(thisIndex);
|
||||||
restTemplate.refresh(IndexCoordinates.of(thatIndex));
|
restTemplate.refresh(thatIndex);
|
||||||
|
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() //
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() //
|
||||||
.withQuery(termQuery("message", "negative")) //
|
.withQuery(termQuery("message", "negative")) //
|
||||||
.withIndices(indexPrefix + "*") //
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
template.deleteBy(searchQuery, SampleEntity.class) //
|
template.deleteBy(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.expectNext(0L) //
|
.expectNext(0L) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
TestUtils.deleteIndex(thisIndex, thatIndex);
|
TestUtils.deleteIndex(thisIndex.getIndexName(), thatIndex.getIndexName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-504
|
@Test // DATAES-504
|
||||||
@ -672,13 +676,12 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
index(entity1, entity2, entity3);
|
index(entity1, entity2, entity3);
|
||||||
|
|
||||||
NativeSearchQuery query = new NativeSearchQueryBuilder() //
|
NativeSearchQuery query = new NativeSearchQueryBuilder() //
|
||||||
.withIndices(DEFAULT_INDEX) //
|
|
||||||
.withQuery(matchAllQuery()) //
|
.withQuery(matchAllQuery()) //
|
||||||
.withCollapseField("rate") //
|
.withCollapseField("rate") //
|
||||||
.withPageable(PageRequest.of(0, 25)) //
|
.withPageable(PageRequest.of(0, 25)) //
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
template.find(query, SampleEntity.class) //
|
template.find(query, SampleEntity.class, IndexCoordinates.of(DEFAULT_INDEX)) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.expectNextCount(2) //
|
.expectNextCount(2) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
@ -725,7 +728,7 @@ public class ReactiveElasticsearchTemplateTests {
|
|||||||
|
|
||||||
private void index(SampleEntity... entities) {
|
private void index(SampleEntity... entities) {
|
||||||
|
|
||||||
IndexCoordinates indexCoordinates = IndexCoordinates.of(DEFAULT_INDEX).withTypes( "test-type");
|
IndexCoordinates indexCoordinates = IndexCoordinates.of(DEFAULT_INDEX).withTypes("test-type");
|
||||||
|
|
||||||
if (entities.length == 1) {
|
if (entities.length == 1) {
|
||||||
restTemplate.index(getIndexQuery(entities[0]), indexCoordinates);
|
restTemplate.index(getIndexQuery(entities[0]), indexCoordinates);
|
||||||
|
@ -57,6 +57,7 @@ import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsea
|
|||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||||
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +70,8 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
@Mock ReactiveElasticsearchClient client;
|
@Mock ReactiveElasticsearchClient client;
|
||||||
ReactiveElasticsearchTemplate template;
|
ReactiveElasticsearchTemplate template;
|
||||||
|
|
||||||
|
private IndexCoordinates index = IndexCoordinates.of("index").withTypes("type");
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
@ -81,7 +84,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
ArgumentCaptor<IndexRequest> captor = ArgumentCaptor.forClass(IndexRequest.class);
|
ArgumentCaptor<IndexRequest> captor = ArgumentCaptor.forClass(IndexRequest.class);
|
||||||
when(client.index(captor.capture())).thenReturn(Mono.empty());
|
when(client.index(captor.capture())).thenReturn(Mono.empty());
|
||||||
|
|
||||||
template.save(Collections.singletonMap("key", "value"), "index", "type") //
|
template.save(Collections.singletonMap("key", "value"), index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -96,7 +99,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
|
|
||||||
template.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
|
template.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
|
||||||
|
|
||||||
template.save(Collections.singletonMap("key", "value"), "index", "type") //
|
template.save(Collections.singletonMap("key", "value"), index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -124,7 +127,8 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
|
|
||||||
template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
|
template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
|
||||||
|
|
||||||
template.find(new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(0, 10)), SampleEntity.class) //
|
Query query = new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(0, 10));
|
||||||
|
template.find(query, SampleEntity.class, index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -137,7 +141,8 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
|
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
|
||||||
when(client.search(captor.capture())).thenReturn(Flux.empty());
|
when(client.search(captor.capture())).thenReturn(Flux.empty());
|
||||||
|
|
||||||
template.find(new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(2, 50)), SampleEntity.class) //
|
Query query = new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(2, 50));
|
||||||
|
template.find(query, SampleEntity.class, index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -164,7 +169,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
ArgumentCaptor<DeleteRequest> captor = ArgumentCaptor.forClass(DeleteRequest.class);
|
ArgumentCaptor<DeleteRequest> captor = ArgumentCaptor.forClass(DeleteRequest.class);
|
||||||
when(client.delete(captor.capture())).thenReturn(Mono.empty());
|
when(client.delete(captor.capture())).thenReturn(Mono.empty());
|
||||||
|
|
||||||
template.deleteById("id", "index", "type") //
|
template.deleteById("id", index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -179,7 +184,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
|
|
||||||
template.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
|
template.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
|
||||||
|
|
||||||
template.deleteById("id", "index", "type") //
|
template.deleteById("id", index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -192,7 +197,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
|
ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
|
||||||
when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
|
when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
|
||||||
|
|
||||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, "index", "type") //
|
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -207,7 +212,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
|
|
||||||
template.setRefreshPolicy(RefreshPolicy.NONE);
|
template.setRefreshPolicy(RefreshPolicy.NONE);
|
||||||
|
|
||||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, "index", "type") //
|
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -220,7 +225,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
|
ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
|
||||||
when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
|
when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
|
||||||
|
|
||||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, "index", "type") //
|
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
@ -235,7 +240,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
|||||||
|
|
||||||
template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
|
template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
|
||||||
|
|
||||||
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, "index", "type") //
|
template.deleteBy(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public class ElasticsearchTemplateAggregationTests {
|
|||||||
.addAuthor(RIZWAN_IDREES).addPublishedYear(YEAR_2002).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000)
|
.addAuthor(RIZWAN_IDREES).addPublishedYear(YEAR_2002).addPublishedYear(YEAR_2001).addPublishedYear(YEAR_2000)
|
||||||
.score(40).buildIndex();
|
.score(40).buildIndex();
|
||||||
|
|
||||||
IndexCoordinates index = IndexCoordinates.of(INDEX_NAME).withTypes( "article");
|
IndexCoordinates index = IndexCoordinates.of(INDEX_NAME).withTypes("article");
|
||||||
elasticsearchTemplate.index(article1, index);
|
elasticsearchTemplate.index(article1, index);
|
||||||
elasticsearchTemplate.index(article2, index);
|
elasticsearchTemplate.index(article2, index);
|
||||||
elasticsearchTemplate.index(article3, index);
|
elasticsearchTemplate.index(article3, index);
|
||||||
@ -111,7 +111,6 @@ public class ElasticsearchTemplateAggregationTests {
|
|||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() //
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() //
|
||||||
.withQuery(matchAllQuery()) //
|
.withQuery(matchAllQuery()) //
|
||||||
.withSearchType(SearchType.DEFAULT) //
|
.withSearchType(SearchType.DEFAULT) //
|
||||||
.withIndices(INDEX_NAME).withTypes("article") //
|
|
||||||
.addAggregation(terms("subjects").field("subject")) //
|
.addAggregation(terms("subjects").field("subject")) //
|
||||||
.build();
|
.build();
|
||||||
// when
|
// when
|
||||||
|
@ -70,7 +70,6 @@ public class SpELEntityTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
||||||
nativeSearchQuery.addIndices("test-index-abz-entity");
|
|
||||||
long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
||||||
assertThat(count).isEqualTo(2);
|
assertThat(count).isEqualTo(2);
|
||||||
}
|
}
|
||||||
@ -86,8 +85,6 @@ public class SpELEntityTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
||||||
nativeSearchQuery.addIndices("test-index-abz-entity");
|
|
||||||
nativeSearchQuery.addTypes("myType");
|
|
||||||
long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
||||||
assertThat(count).isEqualTo(1);
|
assertThat(count).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user