public class ReactiveElasticsearchTemplate extends Object implements ReactiveElasticsearchOperations, ApplicationContextAware
Modifier and Type | Class and Description |
---|---|
protected static interface |
ReactiveElasticsearchTemplate.DocumentCallback<T> |
protected class |
ReactiveElasticsearchTemplate.ReadDocumentCallback<T> |
protected class |
ReactiveElasticsearchTemplate.ReadSearchDocumentCallback<T> |
protected static interface |
ReactiveElasticsearchTemplate.SearchDocumentCallback<T> |
ReactiveElasticsearchOperations.ClientCallback<T extends org.reactivestreams.Publisher<?>>
Modifier and Type | Field and Description |
---|---|
protected org.springframework.data.elasticsearch.core.RequestFactory |
requestFactory |
Constructor and Description |
---|
ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client) |
ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client,
ElasticsearchConverter converter) |
Modifier and Type | Method and Description |
---|---|
reactor.core.publisher.Flux<org.elasticsearch.search.aggregations.Aggregation> |
aggregate(Query query,
Class<?> entityType)
Perform an aggregation specified by the given
query . |
reactor.core.publisher.Flux<org.elasticsearch.search.aggregations.Aggregation> |
aggregate(Query query,
Class<?> entityType,
IndexCoordinates index)
Perform an aggregation specified by the given
query . |
reactor.core.publisher.Mono<Void> |
bulkUpdate(List<UpdateQuery> queries,
BulkOptions bulkOptions,
IndexCoordinates index)
Bulk update all objects.
|
protected reactor.core.publisher.Mono<org.elasticsearch.action.bulk.BulkResponse> |
checkForBulkOperationFailure(org.elasticsearch.action.bulk.BulkResponse bulkResponse) |
reactor.core.publisher.Mono<Long> |
count(Query query,
Class<?> entityType)
Count the number of documents matching the given
Query . |
reactor.core.publisher.Mono<Long> |
count(Query query,
Class<?> entityType,
IndexCoordinates index)
Count the number of documents matching the given
Query . |
reactor.core.publisher.Mono<String> |
delete(Object entity)
Delete the given entity extracting index and type from entity metadata.
|
reactor.core.publisher.Mono<String> |
delete(Object entity,
IndexCoordinates index)
Delete the given entity extracting index and type from entity metadata.
|
reactor.core.publisher.Mono<Long> |
delete(Query query,
Class<?> entityType)
Delete the documents matching the given
Query extracting index and type from entity metadata. |
reactor.core.publisher.Mono<Long> |
delete(Query query,
Class<?> entityType,
IndexCoordinates index)
Delete the documents matching the given
Query extracting index and type from entity metadata. |
reactor.core.publisher.Mono<String> |
delete(String id,
Class<?> entityType)
Delete the entity with given id extracting index and type from entity metadata.
|
reactor.core.publisher.Mono<String> |
delete(String id,
IndexCoordinates index)
Delete the entity with given id.
|
protected reactor.core.publisher.Flux<org.elasticsearch.search.aggregations.Aggregation> |
doAggregate(org.elasticsearch.action.search.SearchRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Flux<org.elasticsearch.action.bulk.BulkItemResponse> |
doBulkOperation(List<?> queries,
BulkOptions bulkOptions,
IndexCoordinates index) |
protected reactor.core.publisher.Mono<Long> |
doCount(org.elasticsearch.action.search.SearchRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Mono<String> |
doDelete(org.elasticsearch.action.delete.DeleteRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Mono<org.elasticsearch.index.reindex.BulkByScrollResponse> |
doDeleteBy(org.elasticsearch.index.reindex.DeleteByQueryRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Mono<Boolean> |
doExists(org.elasticsearch.action.get.GetRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Flux<SearchDocument> |
doFind(org.elasticsearch.action.search.SearchRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Mono<org.elasticsearch.index.get.GetResult> |
doGet(org.elasticsearch.action.get.GetRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Mono<org.elasticsearch.action.index.IndexResponse> |
doIndex(org.elasticsearch.action.index.IndexRequest request)
Customization hook on the actual execution result
Publisher . |
protected reactor.core.publisher.Flux<SearchDocument> |
doScroll(org.elasticsearch.action.search.SearchRequest request)
Customization hook on the actual execution result
Publisher . |
<T> org.reactivestreams.Publisher<T> |
execute(ReactiveElasticsearchOperations.ClientCallback<org.reactivestreams.Publisher<T>> callback)
Execute within a
ReactiveElasticsearchOperations.ClientCallback managing resources and translating errors. |
reactor.core.publisher.Mono<Boolean> |
exists(String id,
Class<?> entityType)
Check if an entity with given id exists.
|
reactor.core.publisher.Mono<Boolean> |
exists(String id,
Class<?> entityType,
IndexCoordinates index)
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> |
get(String id,
Class<T> entityType)
Find the document with the given id mapped onto the given entityType.
|
<T> reactor.core.publisher.Mono<T> |
get(String id,
Class<T> entityType,
IndexCoordinates index)
Fetch the entity with given id.
|
protected ReactiveElasticsearchClient |
getClient()
Obtain the
ReactiveElasticsearchClient to operate upon. |
protected reactor.core.publisher.Mono<String> |
getClusterVersion() |
ElasticsearchConverter |
getElasticsearchConverter()
Get the
ElasticsearchConverter used. |
IndexCoordinates |
getIndexCoordinatesFor(Class<?> clazz) |
ElasticsearchPersistentEntity<?> |
getPersistentEntityFor(Class<?> type) |
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<T> |
maybeCallBeforeConvert(T entity,
IndexCoordinates index) |
<T> reactor.core.publisher.Flux<T> |
multiGet(Query query,
Class<T> clazz,
IndexCoordinates index)
Execute a multiGet against elasticsearch for the given ids.
|
protected org.elasticsearch.index.reindex.DeleteByQueryRequest |
prepareDeleteByRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest request)
Customization hook to modify a generated
DeleteByQueryRequest prior to its execution. |
protected org.elasticsearch.action.delete.DeleteRequest |
prepareDeleteRequest(org.elasticsearch.action.delete.DeleteRequest request)
Customization hook to modify a generated
DeleteRequest prior to its execution. |
protected org.elasticsearch.action.index.IndexRequest |
prepareIndexRequest(Object source,
org.elasticsearch.action.index.IndexRequest request)
Customization hook to modify a generated
IndexRequest prior to its execution. |
protected org.elasticsearch.action.search.SearchRequest |
prepareSearchRequest(org.elasticsearch.action.search.SearchRequest request)
Customization hook to modify a generated
SearchRequest prior to its execution. |
protected <R extends org.elasticsearch.action.support.WriteRequest<R>> |
prepareWriteRequest(R request)
Pre process the write request before it is sent to the server, eg. by setting the
refresh policy if applicable. |
<T> reactor.core.publisher.Mono<T> |
save(T entity)
Index the given entity extracting index and type 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>> entitiesPublisher,
IndexCoordinates index)
Index entities under the given type in the given index.
|
<T> reactor.core.publisher.Flux<SearchHit<T>> |
search(Query query,
Class<?> entityType,
Class<T> returnType)
Search the index for entities matching the given
query . |
<T> reactor.core.publisher.Flux<SearchHit<T>> |
search(Query query,
Class<?> entityType,
Class<T> resultType,
IndexCoordinates index)
Search the index for entities matching the given
query . |
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setEntityCallbacks(ReactiveEntityCallbacks entityCallbacks)
Set the
ReactiveEntityCallbacks instance to use when invoking callbacks
like the ReactiveBeforeConvertCallback . |
void |
setIndicesOptions(org.elasticsearch.action.support.IndicesOptions indicesOptions)
Set the default
IndicesOptions for search requests . |
void |
setRefreshPolicy(org.elasticsearch.action.support.WriteRequest.RefreshPolicy refreshPolicy)
Set the default
WriteRequest.RefreshPolicy to apply when writing to Elasticsearch. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
bulkUpdate, delete, findById, findById, save, save, saveAll
protected org.springframework.data.elasticsearch.core.RequestFactory requestFactory
public ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client)
public ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client, ElasticsearchConverter converter)
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
BeansException
public void setEntityCallbacks(ReactiveEntityCallbacks entityCallbacks)
ReactiveEntityCallbacks
instance to use when invoking callbacks
like the ReactiveBeforeConvertCallback
.
Overrides potentially existing ReactiveEntityCallbacks
.entityCallbacks
- must not be null.IllegalArgumentException
- if the given instance is null.public <T> reactor.core.publisher.Mono<T> save(T entity, IndexCoordinates index)
ReactiveDocumentOperations
save
in interface ReactiveDocumentOperations
entity
- must not be null.index
- the target index, must not be nullMono
emitting the saved entity.public <T> reactor.core.publisher.Mono<T> save(T entity)
ReactiveDocumentOperations
save
in interface ReactiveDocumentOperations
entity
- must not be null.Mono
emitting the saved entity.public <T> reactor.core.publisher.Flux<T> saveAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> entitiesPublisher, IndexCoordinates index)
ReactiveDocumentOperations
saveAll
in interface ReactiveDocumentOperations
entitiesPublisher
- must not be null.index
- the target index, must not be nullFlux
emitting saved entities.public <T> reactor.core.publisher.Flux<T> multiGet(Query query, Class<T> clazz, IndexCoordinates index)
ReactiveDocumentOperations
multiGet
in interface ReactiveDocumentOperations
query
- the query defining the ids of the objects to getclazz
- the type of the object to be returnedindex
- the index(es) from which the objects are read.public reactor.core.publisher.Mono<Void> bulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index)
ReactiveDocumentOperations
bulkUpdate
in interface ReactiveDocumentOperations
queries
- the queries to execute in bulkbulkOptions
- options to be added to the bulk requestprotected reactor.core.publisher.Mono<org.elasticsearch.action.index.IndexResponse> doIndex(org.elasticsearch.action.index.IndexRequest request)
Publisher
. request
- the already prepared IndexRequest
ready to be executed.Mono
emitting the result of the operation.protected reactor.core.publisher.Flux<org.elasticsearch.action.bulk.BulkItemResponse> doBulkOperation(List<?> queries, BulkOptions bulkOptions, IndexCoordinates index)
protected reactor.core.publisher.Mono<org.elasticsearch.action.bulk.BulkResponse> checkForBulkOperationFailure(org.elasticsearch.action.bulk.BulkResponse bulkResponse)
public reactor.core.publisher.Mono<Boolean> exists(String id, Class<?> entityType)
ReactiveDocumentOperations
exists
in interface ReactiveDocumentOperations
id
- the _id of the document to look for.entityType
- the domain type used.Mono
emitting true if a matching document exists, false otherwise.public reactor.core.publisher.Mono<Boolean> exists(String id, IndexCoordinates index)
ReactiveDocumentOperations
exists
in interface ReactiveDocumentOperations
id
- the _id of the document to look for.index
- the target index, must not be nullMono
emitting true if a matching document exists, false otherwise.public reactor.core.publisher.Mono<Boolean> exists(String id, Class<?> entityType, IndexCoordinates index)
ReactiveDocumentOperations
exists
in interface ReactiveDocumentOperations
id
- the _id of the document to look for.index
- the target index, must not be nullMono
emitting true if a matching document exists, false otherwise.protected reactor.core.publisher.Mono<Boolean> doExists(org.elasticsearch.action.get.GetRequest request)
Publisher
. request
- the already prepared GetRequest
ready to be executed.Mono
emitting the result of the operation.public <T> reactor.core.publisher.Mono<T> get(String id, Class<T> entityType)
ReactiveDocumentOperations
get
in interface ReactiveDocumentOperations
id
- the _id of the document to fetch.entityType
- the domain type used for mapping the document.Mono.empty()
if not found.public <T> reactor.core.publisher.Mono<T> get(String id, Class<T> entityType, IndexCoordinates index)
ReactiveDocumentOperations
get
in interface ReactiveDocumentOperations
id
- must not be null.index
- the target index, must not be nullMono
emitting the entity or signalling completion if none found.protected reactor.core.publisher.Mono<org.elasticsearch.index.get.GetResult> doGet(org.elasticsearch.action.get.GetRequest request)
Publisher
. request
- the already prepared GetRequest
ready to be executed.Mono
emitting the result of the operation.public reactor.core.publisher.Mono<String> delete(Object entity, IndexCoordinates index)
ReactiveDocumentOperations
delete
in interface ReactiveDocumentOperations
entity
- must not be null.index
- the target index, must not be nullMono
emitting the id of the removed document.public reactor.core.publisher.Mono<String> delete(Object entity)
ReactiveDocumentOperations
delete
in interface ReactiveDocumentOperations
entity
- must not be null.Mono
emitting the id of the removed document.public reactor.core.publisher.Mono<String> delete(String id, Class<?> entityType)
ReactiveDocumentOperations
delete
in interface ReactiveDocumentOperations
id
- must not be null.entityType
- must not be null.Mono
emitting the id of the removed document.public reactor.core.publisher.Mono<String> delete(String id, IndexCoordinates index)
ReactiveDocumentOperations
delete
in interface ReactiveDocumentOperations
id
- must not be null.index
- the target index, must not be nullMono
emitting the id of the removed document.public reactor.core.publisher.Mono<Long> delete(Query query, Class<?> entityType, IndexCoordinates index)
ReactiveDocumentOperations
Query
extracting index and type from entity metadata.delete
in interface ReactiveDocumentOperations
query
- must not be null.entityType
- must not be null.index
- the target index, must not be nullMono
emitting the number of the removed documents.public reactor.core.publisher.Mono<Long> delete(Query query, Class<?> entityType)
ReactiveDocumentOperations
Query
extracting index and type from entity metadata.delete
in interface ReactiveDocumentOperations
query
- must not be null.entityType
- must not be null.Mono
emitting the number of the removed documents.protected reactor.core.publisher.Mono<String> doDelete(org.elasticsearch.action.delete.DeleteRequest request)
Publisher
. request
- the already prepared DeleteRequest
ready to be executed.Mono
emitting the result of the operation.protected reactor.core.publisher.Mono<org.elasticsearch.index.reindex.BulkByScrollResponse> doDeleteBy(org.elasticsearch.index.reindex.DeleteByQueryRequest request)
Publisher
. request
- the already prepared DeleteByQueryRequest
ready to be executed.Mono
emitting the result of the operation.protected org.elasticsearch.action.delete.DeleteRequest prepareDeleteRequest(org.elasticsearch.action.delete.DeleteRequest request)
DeleteRequest
prior to its execution. Eg. by setting the
refresh policy
if applicable.request
- the generated DeleteRequest
.protected org.elasticsearch.index.reindex.DeleteByQueryRequest prepareDeleteByRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest request)
DeleteByQueryRequest
prior to its execution. Eg. by setting the
refresh policy
if applicable.request
- the generated DeleteByQueryRequest
.protected org.elasticsearch.action.index.IndexRequest prepareIndexRequest(Object source, org.elasticsearch.action.index.IndexRequest request)
IndexRequest
prior to its execution. Eg. by setting the
refresh policy
if applicable.source
- the source object the IndexRequest
was derived from.request
- the generated IndexRequest
.protected <R extends org.elasticsearch.action.support.WriteRequest<R>> R prepareWriteRequest(R request)
refresh policy
if applicable.R
- request
- must not be null.WriteRequest
.public <T> reactor.core.publisher.Flux<SearchHit<T>> search(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index)
ReactiveSearchOperations
query
.search
in interface ReactiveSearchOperations
query
- must not be null.entityType
- must not be null.resultType
- the projection result type.index
- the target index, must not be nullFlux
emitting matching entities one by one wrapped in a SearchHit
.public <T> reactor.core.publisher.Flux<SearchHit<T>> search(Query query, Class<?> entityType, Class<T> returnType)
ReactiveSearchOperations
query
. Unpaged
queries may overrule elasticsearch server defaults for page size by either *
delegating to the scroll API or using a max *
size
.search
in interface ReactiveSearchOperations
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. ThFlux
emitting matching entities one by one wrapped in a SearchHit
.public reactor.core.publisher.Flux<org.elasticsearch.search.aggregations.Aggregation> aggregate(Query query, Class<?> entityType)
ReactiveSearchOperations
query
. aggregate
in interface ReactiveSearchOperations
query
- must not be null.entityType
- must not be null.Flux
emitting matching aggregations one by one.public reactor.core.publisher.Flux<org.elasticsearch.search.aggregations.Aggregation> aggregate(Query query, Class<?> entityType, IndexCoordinates index)
ReactiveSearchOperations
query
. aggregate
in interface ReactiveSearchOperations
query
- must not be null.entityType
- must not be null.index
- the target index, must not be nullFlux
emitting matching aggregations one by one.public reactor.core.publisher.Mono<Long> count(Query query, Class<?> entityType)
ReactiveSearchOperations
Query
.count
in interface ReactiveSearchOperations
query
- must not be null.entityType
- must not be null.Mono
emitting the nr of matching documents.public reactor.core.publisher.Mono<Long> count(Query query, Class<?> entityType, IndexCoordinates index)
ReactiveSearchOperations
Query
.count
in interface ReactiveSearchOperations
query
- must not be null.entityType
- must not be null.index
- the target index, must not be nullMono
emitting the nr of matching documents.protected reactor.core.publisher.Flux<SearchDocument> doFind(org.elasticsearch.action.search.SearchRequest request)
Publisher
. request
- the already prepared SearchRequest
ready to be executed.Flux
emitting the result of the operation converted to SearchDocument
s.protected reactor.core.publisher.Flux<org.elasticsearch.search.aggregations.Aggregation> doAggregate(org.elasticsearch.action.search.SearchRequest request)
Publisher
. request
- the already prepared SearchRequest
ready to be executed.Flux
emitting the result of the operation.protected reactor.core.publisher.Mono<Long> doCount(org.elasticsearch.action.search.SearchRequest request)
Publisher
. request
- the already prepared SearchRequest
ready to be executed.Mono
emitting the result of the operation.protected reactor.core.publisher.Flux<SearchDocument> doScroll(org.elasticsearch.action.search.SearchRequest request)
Publisher
. request
- the already prepared SearchRequest
ready to be executed.Flux
emitting the result of the operation converted to SearchDocument
s.protected org.elasticsearch.action.search.SearchRequest prepareSearchRequest(org.elasticsearch.action.search.SearchRequest request)
SearchRequest
prior to its execution. Eg. by setting the
indices options
if applicable.request
- the generated SearchRequest
.protected reactor.core.publisher.Mono<String> getClusterVersion()
public void setRefreshPolicy(@Nullable org.elasticsearch.action.support.WriteRequest.RefreshPolicy refreshPolicy)
WriteRequest.RefreshPolicy
to apply when writing to Elasticsearch.refreshPolicy
- can be null.public void setIndicesOptions(@Nullable org.elasticsearch.action.support.IndicesOptions indicesOptions)
IndicesOptions
for search requests
.indicesOptions
- can be null.public <T> org.reactivestreams.Publisher<T> execute(ReactiveElasticsearchOperations.ClientCallback<org.reactivestreams.Publisher<T>> callback)
ReactiveElasticsearchOperations
ReactiveElasticsearchOperations.ClientCallback
managing resources and translating errors.execute
in interface ReactiveElasticsearchOperations
callback
- must not be null.Publisher
emitting results.public ElasticsearchConverter getElasticsearchConverter()
ReactiveElasticsearchOperations
ElasticsearchConverter
used.getElasticsearchConverter
in interface ReactiveElasticsearchOperations
public IndexCoordinates getIndexCoordinatesFor(Class<?> clazz)
getIndexCoordinatesFor
in interface ReactiveElasticsearchOperations
@Nullable public ElasticsearchPersistentEntity<?> getPersistentEntityFor(@Nullable Class<?> type)
getPersistentEntityFor
in interface ReactiveElasticsearchOperations
protected ReactiveElasticsearchClient getClient()
ReactiveElasticsearchClient
to operate upon.protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeConvert(T entity, IndexCoordinates index)
protected <T> reactor.core.publisher.Mono<T> maybeCallAfterSave(T entity, IndexCoordinates index)
protected <T> reactor.core.publisher.Mono<T> maybeCallAfterConvert(T entity, Document document, IndexCoordinates index)
Copyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.