Module spring.data.elasticsearch
Class AbstractReactiveElasticsearchTemplate
java.lang.Object
org.springframework.data.elasticsearch.core.AbstractReactiveElasticsearchTemplate
- All Implemented Interfaces:
Aware,ApplicationContextAware,ReactiveDocumentOperations,ReactiveElasticsearchOperations,ReactiveSearchOperations,ReactiveScriptOperations,ReactiveSqlOperations
- Direct Known Subclasses:
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 interfaceCallback to convertDocumentinto an entity of type Tprotected classstatic final recordValue class to capture client independent information from a response to an index request.protected classprotected classprotected static interfaceCallback to convert aSearchDocumentinto different other classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ElasticsearchConverterprotected ReactiveEntityCallbacksprotected final EntityOperationsprotected final SimpleElasticsearchMappingContextprotected RefreshPolicyprotected RoutingResolverFields inherited from interface org.springframework.data.elasticsearch.core.ReactiveDocumentOperations
FLUX_SAVE_BULK_SIZE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionFlux<? extends AggregationContainer<?>>Perform an aggregation specified by the givenquery.closePointInTime(String pit) Closes a point in timeCount the number of documents matching the givenQuery.count(Query query, Class<?> entityType, IndexCoordinates index) Count the number of documents matching the givenQuery.Delete the given entity extracting index from entity metadata.delete(Object entity, IndexCoordinates index) Delete the given entity extracting index from entity metadata.Delete the entity with given id extracting index from entity metadata.delete(String id, IndexCoordinates index) Delete the entity with given id.delete(DeleteQuery query, Class<?> entityType) Delete the documents matching the givenQueryextracting index from entity metadata.deleteScript(String name) Deletes the script with the given nameprotected abstract AbstractReactiveElasticsearchTemplatedoCopy()doCount(Query query, Class<?> entityType, IndexCoordinates index) doDeleteById(String id, String routing, IndexCoordinates index) doExists(String id, IndexCoordinates index) protected abstract Flux<SearchDocument>doFind(Query query, Class<?> clazz, IndexCoordinates index) protected abstract <T> Mono<SearchDocumentResponse>doFindForResponse(Query query, Class<?> clazz, IndexCoordinates index) protected abstract <T> Mono<Tuple2<T,AbstractReactiveElasticsearchTemplate.IndexResponseMetaData>> doIndex(T entity, IndexCoordinates index) Check if an entity with given id exists.exists(String id, IndexCoordinates index) Check if an entity with given id exists.<T> Mono<T>Find the document with the given id mapped onto the given entityType.Get theElasticsearchConverterused.getEntityRouting(Object entity) gets the routing for an entity.getIndexCoordinatesFor(Class<?> clazz) protected IndexQuerygetIndexQuery(Object value) getPersistentEntityFor(Class<?> type) Gest the script with the given name.logs the versions of the different Elasticsearch components.protected <T> Mono<T>maybeCallbackAfterConvert(T entity, Document document, IndexCoordinates index) maybeCallbackAfterLoad(Document document, Class<T> type, IndexCoordinates index) protected <T> Mono<T>maybeCallbackAfterSave(T entity, IndexCoordinates index) protected <T> Mono<T>maybeCallbackBeforeConvert(T entity, IndexCoordinates index) <T> Flux<MultiGetItem<T>>Execute a multiGet against elasticsearch for the given ids.openPointInTime(IndexCoordinates index, Duration keepAlive, Boolean ignoreUnavailable) Opens a point in time (pit) in Elasticsearch.Stores the given script in the Elasticsearch cluster.<T> Flux<T>Indexes the entities into the index extracted from entity metadata.<T> Flux<T>save(Flux<T> entities, IndexCoordinates index, int bulkSize) Indexes the entities into the given index.<T> Mono<T>save(T entity) Index the given entity extracting index from entity metadata.<T> Mono<T>save(T entity, IndexCoordinates index) Index the entity under the given type in the given index.<T> Flux<T>saveAll(Mono<? extends Collection<? extends T>> entities, Class<T> clazz) Index entities in the index extracted from entity metadata.Search the index for entities matching the givenquery.search(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index) Search the index for entities matching the givenquery.<T> 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> 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> Mono<SearchPage<T>>searchForPage(Query query, Class<?> entityType, Class<T> resultType) Search the index for entities matching the givenquery.<T> 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.Does a suggest query.suggest(Query query, Class<?> entityType, IndexCoordinates index) Does a suggest query.withRefreshPolicy(RefreshPolicy refreshPolicy) Returns a copy of this instance with the same configuration, but that uses a differentRefreshPolicy.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, save, save, saveAll, saveAll, saveAll, submitReindex, update, updateByQueryMethods inherited from interface org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations
cluster, indexOps, indexOpsMethods inherited from interface org.springframework.data.elasticsearch.core.ReactiveSearchOperations
aggregate, count, idsQuery, matchAllQuery, openPointInTime, queryBuilderWithIds, search, search, searchForHits, searchForHits, searchForPage, searchForPageMethods inherited from interface org.springframework.data.elasticsearch.core.sql.ReactiveSqlOperations
search
-
Field Details
-
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
-
withRefreshPolicy
Description copied from interface:ReactiveElasticsearchOperationsReturns a copy of this instance with the same configuration, but that uses a differentRefreshPolicy.- Specified by:
withRefreshPolicyin interfaceReactiveElasticsearchOperations- Parameters:
refreshPolicy- theRefreshPolicyvalue.- Returns:
ReactiveElasticsearchOperationsinstance.
-
save
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.
-
save
Description copied from interface:ReactiveDocumentOperationsIndexes the entities into the index extracted from entity metadata. The entities are collected into batches of {bulkSize} with a maximal timeout of 200 ms, seeFlux.bufferTimeout(int, java.time.Duration)and then sent in a bulk operation to Elasticsearch.- Specified by:
savein interfaceReactiveDocumentOperations- Type Parameters:
T- entity typeclazz- the class to get the index name frombulkSize- number of entities to put in a bulk request- Returns:
- a Flux emitting the saved entities
-
save
Description copied from interface:ReactiveDocumentOperationsIndexes the entities into the given index. The entities are collected into batches of {bulkSize} with a maximal timeout of 200 ms, see {@link reactor.core.publisher.Flux#bufferTimeout(int, java.time * .Duration)} and then sent in a bulk operation to Elasticsearch.- Specified by:
savein interfaceReactiveDocumentOperations- Type Parameters:
T- entity type- Parameters:
entities- the entities to saveindex- the index to save tobulkSize- number of entities to put in a bulk request- Returns:
- a Flux emitting the saved entities
-
saveAll
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
-
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> Mono<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
-
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> 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
Description copied from interface:ReactiveSearchOperationsSearch the index for entities matching the givenquery.- 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
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> 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> 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> 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
-
doFindForResponse
protected abstract <T> Mono<SearchDocumentResponse> doFindForResponse(Query query, Class<?> clazz, IndexCoordinates index) -
aggregate
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 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
Description copied from interface:ReactiveSearchOperationsDoes a suggest query.- Specified by:
suggestin interfaceReactiveSearchOperations- Parameters:
query- the Query containing the suggest definition. 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
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
-
openPointInTime
public Mono<String> openPointInTime(IndexCoordinates index, Duration keepAlive, Boolean ignoreUnavailable) Description copied from interface:ReactiveSearchOperationsOpens a point in time (pit) in Elasticsearch.- Specified by:
openPointInTimein interfaceReactiveSearchOperations- Parameters:
index- the index name(s) to usekeepAlive- the duration the pit shoult be kept aliveignoreUnavailable- if {$literal true} the call will fail if any of the indices is missing or closed- Returns:
- the pit identifier
-
closePointInTime
Description copied from interface:ReactiveSearchOperationsCloses a point in time- Specified by:
closePointInTimein interfaceReactiveSearchOperations- Parameters:
pit- the pit identifier as returned byReactiveSearchOperations.openPointInTime(IndexCoordinates, Duration, Boolean)- Returns:
- true on success
-
maybeCallbackBeforeConvert
-
maybeCallbackAfterSave
-
maybeCallbackAfterConvert
protected <T> Mono<T> maybeCallbackAfterConvert(T entity, Document document, IndexCoordinates index) -
maybeCallbackAfterLoad
protected <T> Mono<Document> maybeCallbackAfterLoad(Document document, Class<T> type, IndexCoordinates index) -
putScript
Description copied from interface:ReactiveScriptOperationsStores the given script in the Elasticsearch cluster.- Specified by:
putScriptin interfaceReactiveScriptOperations- Returns:
- {true if successful
-
getScript
Description copied from interface:ReactiveScriptOperationsGest the script with the given name.- Specified by:
getScriptin interfaceReactiveScriptOperations- Parameters:
name- the name of the script- Returns:
- Script or null when a script with this name does not exist.
-
deleteScript
Description copied from interface:ReactiveScriptOperationsDeletes the script with the given name- Specified by:
deleteScriptin interfaceReactiveScriptOperations- Parameters:
name- the name of the script.- Returns:
- true if the request was acknowledged by the cluster.
-
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
-
getEntityRouting
Description copied from interface:ReactiveElasticsearchOperationsgets the routing for an entity.- Specified by:
getEntityRoutingin interfaceReactiveElasticsearchOperations- Parameters:
entity- the entity- Returns:
- the routing, may be null if not set.
-