Class AbstractReactiveElasticsearchTemplate
java.lang.Object
org.springframework.data.elasticsearch.core.AbstractReactiveElasticsearchTemplate
- All Implemented Interfaces:
Aware,ApplicationContextAware,ReactiveDocumentOperations,ReactiveElasticsearchOperations,ReactiveSearchOperations
- Direct Known Subclasses:
ReactiveElasticsearchTemplate,ReactiveElasticsearchTemplate
public abstract class AbstractReactiveElasticsearchTemplate
extends Object
implements ReactiveElasticsearchOperations, ApplicationContextAware
Base class keeping common code for implementations of the
ReactiveElasticsearchOperations interface
independent of the used client.- Since:
- 4.4
- Author:
- Peter-Josef Meisch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceprotected classstatic classValue class to capture client independent information from a response to an index request.protected classprotected classprotected static interfaceNested classes/interfaces inherited from interface org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations
ReactiveElasticsearchOperations.ClientCallback<T extends org.reactivestreams.Publisher<?>>, ReactiveElasticsearchOperations.ClusterClientCallback<T extends org.reactivestreams.Publisher<?>>, ReactiveElasticsearchOperations.IndicesClientCallback<T extends org.reactivestreams.Publisher<?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ElasticsearchConverterprotected ReactiveEntityCallbacksprotected final EntityOperationsprotected final SimpleElasticsearchMappingContextprotected static final org.slf4j.Loggerprotected RefreshPolicyprotected RoutingResolver -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Flux<AggregationContainer<?>>Perform an aggregation specified by the givenquery.reactor.core.publisher.Mono<Long>Count the number of documents matching the givenQuery.reactor.core.publisher.Mono<Long>count(Query query, Class<?> entityType, IndexCoordinates index) Count the number of documents matching the givenQuery.reactor.core.publisher.Mono<String>Delete the given entity extracting index from entity metadata.reactor.core.publisher.Mono<String>delete(Object entity, IndexCoordinates index) Delete the given entity extracting index from entity metadata.reactor.core.publisher.Mono<String>Delete the entity with given id extracting index from entity metadata.reactor.core.publisher.Mono<String>delete(String id, IndexCoordinates index) Delete the entity with given id.reactor.core.publisher.Mono<ByQueryResponse>Delete the documents matching the givenQueryextracting index from entity metadata.protected abstract AbstractReactiveElasticsearchTemplatedoCopy()protected abstract reactor.core.publisher.Mono<Long>doCount(Query query, Class<?> entityType, IndexCoordinates index) protected abstract reactor.core.publisher.Mono<String>doDeleteById(String id, String routing, IndexCoordinates index) protected abstract reactor.core.publisher.Mono<Boolean>doExists(String id, IndexCoordinates index) protected abstract reactor.core.publisher.Flux<SearchDocument>doFind(Query query, Class<?> clazz, IndexCoordinates index) protected abstract <T> reactor.core.publisher.Mono<SearchDocumentResponse>doFindForResponse(Query query, Class<?> clazz, IndexCoordinates index) protected abstract <T> reactor.core.publisher.Mono<reactor.util.function.Tuple2<T,AbstractReactiveElasticsearchTemplate.IndexResponseMetaData>> doIndex(T entity, IndexCoordinates index) reactor.core.publisher.Mono<Boolean>Check if an entity with given id exists.reactor.core.publisher.Mono<Boolean>exists(String id, IndexCoordinates index) Check if an entity with given id exists.<T> reactor.core.publisher.Mono<T>Find the document with the given id mapped onto the given entityType.protected abstract reactor.core.publisher.Mono<String>Get theElasticsearchConverterused.getIndexCoordinatesFor(Class<?> clazz) protected IndexQuerygetIndexQuery(Object value) getPersistentEntityFor(Class<?> type) protected abstract reactor.core.publisher.Mono<String>protected abstract reactor.core.publisher.Mono<String>reactor.core.publisher.Mono<Void>logs the versions of the different Elasticsearch components.protected <T> reactor.core.publisher.Mono<T>maybeCallAfterConvert(T entity, Document document, IndexCoordinates index) protected <T> reactor.core.publisher.Mono<T>maybeCallAfterSave(T entity, IndexCoordinates index) protected <T> reactor.core.publisher.Mono<Document>maybeCallbackAfterLoad(Document document, Class<T> type, IndexCoordinates index) protected <T> reactor.core.publisher.Mono<T>maybeCallBeforeConvert(T entity, IndexCoordinates index) <T> reactor.core.publisher.Flux<MultiGetItem<T>>Execute a multiGet against elasticsearch for the given ids.<T> reactor.core.publisher.Mono<T>save(T entity) Index the given entity extracting index from entity metadata.<T> reactor.core.publisher.Mono<T>save(T entity, IndexCoordinates index) Index the entity under the given type in the given index.<T> reactor.core.publisher.Flux<T>saveAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> entities, Class<T> clazz) Index entities in the index extracted from entity metadata.<T> reactor.core.publisher.Flux<SearchHit<T>>Search the index for entities matching the givenquery.<T> reactor.core.publisher.Flux<SearchHit<T>>search(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) Search the index for entities matching the givenquery.<T> reactor.core.publisher.Mono<ReactiveSearchHits<T>>searchForHits(Query query, Class<?> entityType, Class<T> resultType) Perform a search and return theReactiveSearchHitswhich contains information about the search results and which will provide the documents by theReactiveSearchHits.getSearchHits()method.<T> reactor.core.publisher.Mono<ReactiveSearchHits<T>>searchForHits(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) Perform a search and return theReactiveSearchHitswhich contains information about the search results and which will provide the documents by theReactiveSearchHits.getSearchHits()method.<T> reactor.core.publisher.Mono<SearchPage<T>>searchForPage(Query query, Class<?> entityType, Class<T> resultType) Search the index for entities matching the givenquery.<T> reactor.core.publisher.Mono<SearchPage<T>>searchForPage(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) Search the index for entities matching the givenquery.voidsetApplicationContext(ApplicationContext applicationContext) voidsetEntityCallbacks(ReactiveEntityCallbacks entityCallbacks) Set theReactiveEntityCallbacksinstance to use when invokingcallbackslike theReactiveBeforeConvertCallback.voidsetRefreshPolicy(RefreshPolicy refreshPolicy) Set the defaultRefreshPolicyto apply when writing to Elasticsearch.reactor.core.publisher.Mono<Suggest>Does a suggest query.reactor.core.publisher.Mono<Suggest>suggest(Query query, Class<?> entityType, IndexCoordinates index) Does a suggest query.protected <T> TupdateIndexedObject(T entity, IndexedObjectInformation indexedObjectInformation) withRouting(RoutingResolver routingResolver) Returns a copy of this instance with the same configuration, but that uses a differentRoutingResolverto obtain routing information.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.elasticsearch.core.ReactiveDocumentOperations
bulkUpdate, bulkUpdate, delete, get, multiGet, reindex, save, save, saveAll, saveAll, saveAll, submitReindex, update, updateByQueryMethods inherited from interface org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations
cluster, execute, executeWithClusterClient, executeWithIndicesClient, indexOps, indexOpsMethods inherited from interface org.springframework.data.elasticsearch.core.ReactiveSearchOperations
aggregate, count, idsQuery, matchAllQuery, search, search, searchForHits, searchForHits, searchForPage, searchForPage, suggest, suggest
-
Field Details
-
QUERY_LOGGER
protected static final org.slf4j.Logger QUERY_LOGGER -
converter
-
mappingContext
-
entityOperations
-
refreshPolicy
-
routingResolver
-
entityCallbacks
-
-
Constructor Details
-
AbstractReactiveElasticsearchTemplate
-
-
Method Details
-
getElasticsearchConverter
Description copied from interface:ReactiveElasticsearchOperationsGet theElasticsearchConverterused.- Specified by:
getElasticsearchConverterin interfaceReactiveElasticsearchOperations- Returns:
- never null
-
doCopy
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
setRefreshPolicy
Set the defaultRefreshPolicyto apply when writing to Elasticsearch.- Parameters:
refreshPolicy- can be null.
-
getRefreshPolicy
- Returns:
- the current
RefreshPolicy.
-
setEntityCallbacks
Set theReactiveEntityCallbacksinstance to use when invokingcallbackslike theReactiveBeforeConvertCallback. Overrides potentially existingReactiveEntityCallbacks.- Parameters:
entityCallbacks- must not be null.- Throws:
IllegalArgumentException- if the given instance is null.- Since:
- 4.0
-
logVersions
logs the versions of the different Elasticsearch components.- Returns:
- a Mono signalling finished execution
- Since:
- 4.3
-
withRouting
Description copied from interface:ReactiveElasticsearchOperationsReturns a copy of this instance with the same configuration, but that uses a differentRoutingResolverto obtain routing information.- Specified by:
withRoutingin interfaceReactiveElasticsearchOperations- Parameters:
routingResolver- theRoutingResolvervalue, must not be null.- Returns:
- DocumentOperations instance
-
save
public <T> reactor.core.publisher.Mono<T> save(T entity) Description copied from interface:ReactiveDocumentOperationsIndex the given entity extracting index from entity metadata.- Specified by:
savein interfaceReactiveDocumentOperations- Parameters:
entity- must not be null.- Returns:
- a
Monoemitting the saved entity.
-
saveAll
public <T> reactor.core.publisher.Flux<T> saveAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> entities, Class<T> clazz) Description copied from interface:ReactiveDocumentOperationsIndex entities in the index extracted from entity metadata.- Specified by:
saveAllin interfaceReactiveDocumentOperations- Parameters:
entities- must not be null.clazz- the entity class, used to determine the index- Returns:
- a
Fluxemitting saved entities.
-
getIndexQuery
-
updateIndexedObject
-
multiGet
Description copied from interface:ReactiveDocumentOperationsExecute a multiGet against elasticsearch for the given ids.- Specified by:
multiGetin interfaceReactiveDocumentOperations- Parameters:
query- the query defining the ids of the objects to getclazz- the type of the object to be returned, used to determine the index- Returns:
- flux with list of
MultiGetItems that contain the entities - See Also:
-
exists
Description copied from interface:ReactiveDocumentOperationsCheck if an entity with given id exists.- Specified by:
existsin interfaceReactiveDocumentOperations- Parameters:
id- the _id of the document to look for.entityType- the domain type used.- Returns:
- a
Monoemitting true if a matching document exists, false otherwise.
-
exists
Description copied from interface:ReactiveDocumentOperationsCheck if an entity with given id exists.- Specified by:
existsin interfaceReactiveDocumentOperations- Parameters:
id- the _id of the document to look for.index- the target index, must not be null- Returns:
- a
Monoemitting true if a matching document exists, false otherwise.
-
save
Description copied from interface:ReactiveDocumentOperationsIndex the entity under the given type in the given index. If the index is null or empty the index name provided via entity metadata is used. Same for the type.- Specified by:
savein interfaceReactiveDocumentOperations- Parameters:
entity- must not be null.index- the target index, must not be null- Returns:
- a
Monoemitting the saved entity.
-
doIndex
protected abstract <T> reactor.core.publisher.Mono<reactor.util.function.Tuple2<T,AbstractReactiveElasticsearchTemplate.IndexResponseMetaData>> doIndex(T entity, IndexCoordinates index) -
doExists
-
get
Description copied from interface:ReactiveDocumentOperationsFind the document with the given id mapped onto the given entityType.- Specified by:
getin interfaceReactiveDocumentOperations- Parameters:
id- the _id of the document to fetch.entityType- the domain type used for mapping the document.- Returns:
Mono.empty()if not found.
-
delete
Description copied from interface:ReactiveDocumentOperationsDelete the given entity extracting index from entity metadata.- Specified by:
deletein interfaceReactiveDocumentOperations- Parameters:
entity- must not be null.index- the target index, must not be null- Returns:
- a
Monoemitting the id of the removed document.
-
delete
Description copied from interface:ReactiveDocumentOperationsDelete the given entity extracting index from entity metadata.- Specified by:
deletein interfaceReactiveDocumentOperations- Parameters:
entity- must not be null.- Returns:
- a
Monoemitting the id of the removed document.
-
delete
Description copied from interface:ReactiveDocumentOperationsDelete the entity with given id extracting index from entity metadata.- Specified by:
deletein interfaceReactiveDocumentOperations- Parameters:
id- must not be null.entityType- must not be null.- Returns:
- a
Monoemitting the id of the removed document.
-
delete
Description copied from interface:ReactiveDocumentOperationsDelete the entity with given id.- Specified by:
deletein interfaceReactiveDocumentOperations- Parameters:
id- must not be null.index- the target index, must not be null- Returns:
- a
Monoemitting the id of the removed document.
-
doDeleteById
protected abstract reactor.core.publisher.Mono<String> doDeleteById(String id, @Nullable String routing, IndexCoordinates index) -
delete
Description copied from interface:ReactiveDocumentOperationsDelete the documents matching the givenQueryextracting index from entity metadata.- Specified by:
deletein interfaceReactiveDocumentOperations- Parameters:
query- must not be null.entityType- must not be null.- Returns:
- a
Monoemitting the number of the removed documents.
-
search
public <T> reactor.core.publisher.Flux<SearchHit<T>> search(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) Description copied from interface:ReactiveSearchOperationsSearch the index for entities matching the givenquery.- Specified by:
searchin interfaceReactiveSearchOperations- Parameters:
query- must not be null.entityType- must not be null.resultType- the projection result type.index- the target index, must not be null- Returns:
- a
Fluxemitting matching entities one by one wrapped in aSearchHit.
-
search
public <T> reactor.core.publisher.Flux<SearchHit<T>> search(Query query, Class<?> entityType, Class<T> returnType) Description copied from interface:ReactiveSearchOperationsSearch the index for entities matching the givenquery.
Unpagedqueries may overrule elasticsearch server defaults for page size by either * delegating to the scroll API or using a max* size.- Specified by:
searchin interfaceReactiveSearchOperations- Parameters:
query- must not be null.entityType- The entity type for mapping the query. Must not be null.returnType- The mapping target type. Must not be null. Th- Returns:
- a
Fluxemitting matching entities one by one wrapped in aSearchHit.
-
searchForPage
public <T> reactor.core.publisher.Mono<SearchPage<T>> searchForPage(Query query, Class<?> entityType, Class<T> resultType) Description copied from interface:ReactiveSearchOperationsSearch the index for entities matching the givenquery.- Specified by:
searchForPagein interfaceReactiveSearchOperations- Parameters:
query- must not be null.entityType- must not be null.resultType- the projection result type.- Returns:
- a
Monoemitting matching entities in aSearchHits.
-
searchForPage
public <T> reactor.core.publisher.Mono<SearchPage<T>> searchForPage(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) Description copied from interface:ReactiveSearchOperationsSearch the index for entities matching the givenquery.- Specified by:
searchForPagein interfaceReactiveSearchOperations- Parameters:
query- must not be null.entityType- must not be null.resultType- the projection result type.index- the target index, must not be null- Returns:
- a
Monoemitting matching entities in aSearchHits.
-
searchForHits
public <T> reactor.core.publisher.Mono<ReactiveSearchHits<T>> searchForHits(Query query, Class<?> entityType, Class<T> resultType) Description copied from interface:ReactiveSearchOperationsPerform a search and return theReactiveSearchHitswhich contains information about the search results and which will provide the documents by theReactiveSearchHits.getSearchHits()method.- Specified by:
searchForHitsin interfaceReactiveSearchOperations- Type Parameters:
T- the result type class- Parameters:
query- must not be null.entityType- must not be null.resultType- the projection result type.- Returns:
- a
Monoemitting theReactiveSearchHitsthat contains the search result information
-
searchForHits
public <T> reactor.core.publisher.Mono<ReactiveSearchHits<T>> searchForHits(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) Description copied from interface:ReactiveSearchOperationsPerform a search and return theReactiveSearchHitswhich contains information about the search results and which will provide the documents by theReactiveSearchHits.getSearchHits()method.- Specified by:
searchForHitsin interfaceReactiveSearchOperations- Type Parameters:
T- the result type class- Parameters:
query- must not be null.entityType- must not be null.resultType- the projection result type.index- the target index, must not be null- Returns:
- a
Monoemitting theReactiveSearchHitsthat contains the search result information
-
doFind
protected abstract reactor.core.publisher.Flux<SearchDocument> doFind(Query query, Class<?> clazz, IndexCoordinates index) -
doFindForResponse
protected abstract <T> reactor.core.publisher.Mono<SearchDocumentResponse> doFindForResponse(Query query, Class<?> clazz, IndexCoordinates index) -
aggregate
public reactor.core.publisher.Flux<AggregationContainer<?>> aggregate(Query query, Class<?> entityType) Description copied from interface:ReactiveSearchOperationsPerform an aggregation specified by the givenquery.- Specified by:
aggregatein interfaceReactiveSearchOperations- Parameters:
query- must not be null.entityType- must not be null.- Returns:
- a
Fluxemitting matching aggregations one by one.
-
suggest
Description copied from interface:ReactiveSearchOperationsDoes a suggest query.- Specified by:
suggestin interfaceReactiveSearchOperations- Parameters:
query- the Query containing the suggest definition. Must be currently aNativeSearchQuery, must not be null.entityType- the type of the entities that might be returned for a completion suggestion, must not be null.- Returns:
- suggest data
-
suggest
public reactor.core.publisher.Mono<Suggest> suggest(Query query, Class<?> entityType, IndexCoordinates index) Description copied from interface:ReactiveSearchOperationsDoes a suggest query.- Specified by:
suggestin interfaceReactiveSearchOperations- Parameters:
query- the Query containing the suggest definition. Must be currently aNativeSearchQuery, must not be null.entityType- the type of the entities that might be returned for a completion suggestion, must not be null.index- the index to run the query against, must not be null.- Returns:
- suggest data
-
count
Description copied from interface:ReactiveSearchOperationsCount the number of documents matching the givenQuery.- Specified by:
countin interfaceReactiveSearchOperations- Parameters:
query- must not be null.entityType- must not be null.- Returns:
- a
Monoemitting the nr of matching documents.
-
count
public reactor.core.publisher.Mono<Long> count(Query query, Class<?> entityType, IndexCoordinates index) Description copied from interface:ReactiveSearchOperationsCount the number of documents matching the givenQuery.- Specified by:
countin interfaceReactiveSearchOperations- Parameters:
query- must not be null.entityType- must not be null.index- the target index, must not be null- Returns:
- a
Monoemitting the nr of matching documents.
-
doCount
protected abstract reactor.core.publisher.Mono<Long> doCount(Query query, Class<?> entityType, IndexCoordinates index) -
maybeCallBeforeConvert
protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeConvert(T entity, IndexCoordinates index) -
maybeCallAfterSave
-
maybeCallAfterConvert
protected <T> reactor.core.publisher.Mono<T> maybeCallAfterConvert(T entity, Document document, IndexCoordinates index) -
maybeCallbackAfterLoad
protected <T> reactor.core.publisher.Mono<Document> maybeCallbackAfterLoad(Document document, Class<T> type, IndexCoordinates index) -
getIndexCoordinatesFor
- Specified by:
getIndexCoordinatesForin interfaceReactiveElasticsearchOperations- Returns:
- the IndexCoordinates defined on the entity.
-
getPersistentEntityFor
- Specified by:
getPersistentEntityForin interfaceReactiveElasticsearchOperations
-
getVendor
- Returns:
- the vendor name of the used cluster and client library
- Since:
- 4.3
-
getRuntimeLibraryVersion
- Returns:
- the version of the used client runtime library.
- Since:
- 4.3
-
getClusterVersion
-