Class ReactiveElasticsearchTemplate

java.lang.Object
org.springframework.data.elasticsearch.core.AbstractReactiveElasticsearchTemplate
org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate
All Implemented Interfaces:
Aware, ApplicationContextAware, ReactiveDocumentOperations, ReactiveElasticsearchOperations, ReactiveSearchOperations

public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearchTemplate
Since:
3.2
Author:
Christoph Strobl, Mark Paluch, Farid Azaza, Martin Choraine, Peter-Josef Meisch, Mathias Teier, Aleksei Arsenev, Roman Puchkovskiy, Russell Parry, Thomas Geese, Farid Faoudi, Sijia Liu
  • Field Details

    • requestFactory

      protected org.springframework.data.elasticsearch.core.RequestFactory requestFactory
  • Constructor Details

  • Method Details

    • doCopy

      protected ReactiveElasticsearchTemplate doCopy()
      Specified by:
      doCopy in class AbstractReactiveElasticsearchTemplate
    • setIndicesOptions

      public void setIndicesOptions(@Nullable org.elasticsearch.action.support.IndicesOptions indicesOptions)
      Set the default IndicesOptions for search requests.
      Parameters:
      indicesOptions - can be null.
    • saveAll

      public <T> reactor.core.publisher.Flux<T> saveAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> entitiesPublisher, IndexCoordinates index)
      Description copied from interface: ReactiveDocumentOperations
      Index entities in the given index. If the index is null or empty the index name provided via entity metadata is used.
      Parameters:
      entitiesPublisher - must not be null.
      index - the target index, must not be null
      Returns:
      a Flux emitting saved entities.
    • multiGet

      public <T> reactor.core.publisher.Flux<MultiGetItem<T>> multiGet(Query query, Class<T> clazz, IndexCoordinates index)
      Description copied from interface: ReactiveDocumentOperations
      Execute a multiGet against elasticsearch for the given ids.
      Parameters:
      query - the query defining the ids of the objects to get
      clazz - the type of the object to be returned
      index - the index(es) from which the objects are read.
      Returns:
      flux with list of MultiGetItems that contain the entities
      See Also:
    • doIndex

      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.
      You know what you're doing here? Well fair enough, go ahead on your own risk.
      Parameters:
      request - the already prepared IndexRequest ready to be executed.
      Returns:
      a Mono emitting the result of the operation.
    • bulkUpdate

      public reactor.core.publisher.Mono<Void> bulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index)
      Description copied from interface: ReactiveDocumentOperations
      Bulk update all objects. Will do update.
      Parameters:
      queries - the queries to execute in bulk
      bulkOptions - options to be added to the bulk request
    • doBulkOperation

      protected reactor.core.publisher.Flux<org.elasticsearch.action.bulk.BulkItemResponse> doBulkOperation(List<?> queries, BulkOptions bulkOptions, IndexCoordinates index)
    • checkForBulkOperationFailure

      protected reactor.core.publisher.Mono<org.elasticsearch.action.bulk.BulkResponse> checkForBulkOperationFailure(org.elasticsearch.action.bulk.BulkResponse bulkResponse)
    • doExists

      protected reactor.core.publisher.Mono<Boolean> doExists(String id, IndexCoordinates index)
      Specified by:
      doExists in class AbstractReactiveElasticsearchTemplate
    • doExists

      protected reactor.core.publisher.Mono<Boolean> doExists(org.elasticsearch.action.get.GetRequest request)
      Customization hook on the actual execution result Publisher.
      Parameters:
      request - the already prepared GetRequest ready to be executed.
      Returns:
      a Mono emitting the result of the operation.
    • doIndex

      protected <T> reactor.core.publisher.Mono<reactor.util.function.Tuple2<T,AbstractReactiveElasticsearchTemplate.IndexResponseMetaData>> doIndex(T entity, IndexCoordinates index)
      Specified by:
      doIndex in class AbstractReactiveElasticsearchTemplate
    • get

      public <T> reactor.core.publisher.Mono<T> get(String id, Class<T> entityType, IndexCoordinates index)
      Description copied from interface: ReactiveDocumentOperations
      Fetch the entity with given id.
      Parameters:
      id - must not be null.
      index - the target index, must not be null
      Returns:
      the Mono emitting the entity or signalling completion if none found.
    • doGet

      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.
      Parameters:
      request - the already prepared GetRequest ready to be executed.
      Returns:
      a Mono emitting the result of the operation.
    • doDeleteById

      protected reactor.core.publisher.Mono<String> doDeleteById(String id, @Nullable String routing, IndexCoordinates index)
      Specified by:
      doDeleteById in class AbstractReactiveElasticsearchTemplate
    • delete

      public reactor.core.publisher.Mono<ByQueryResponse> delete(Query query, Class<?> entityType, IndexCoordinates index)
      Description copied from interface: ReactiveDocumentOperations
      Delete the documents matching the given Query extracting index from entity metadata.
      Parameters:
      query - must not be null.
      entityType - must not be null.
      index - the target index, must not be null
      Returns:
      a Mono emitting the number of the removed documents.
    • update

      public reactor.core.publisher.Mono<UpdateResponse> update(UpdateQuery updateQuery, IndexCoordinates index)
      Description copied from interface: ReactiveDocumentOperations
      Partial update of the document.
      Parameters:
      updateQuery - query defining the update
      index - the index where to update the records
      Returns:
      a Mono emitting the update response
    • updateByQuery

      public reactor.core.publisher.Mono<ByQueryResponse> updateByQuery(UpdateQuery updateQuery, IndexCoordinates index)
      Description copied from interface: ReactiveDocumentOperations
      Update document(s) by query.
      Parameters:
      updateQuery - query defining the update, must not be null
      index - the index where to update the records, must not be null
      Returns:
      a Mono emitting the update response
    • reindex

      public reactor.core.publisher.Mono<ReindexResponse> reindex(ReindexRequest postReindexRequest)
      Description copied from interface: ReactiveDocumentOperations
      Copies documents from a source to a destination. The source can be any existing index, alias, or data stream. The destination must differ from the source. For example, you cannot reindex a data stream into itself. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
      Parameters:
      postReindexRequest - reindex request parameters
      Returns:
      a Mono emitting the reindex response
    • submitReindex

      public reactor.core.publisher.Mono<String> submitReindex(ReindexRequest postReindexRequest)
      Description copied from interface: ReactiveDocumentOperations
      Submits a reindex task. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
      Parameters:
      postReindexRequest - reindex request parameters
      Returns:
      a Mono emitting the task id.
    • doDeleteBy

      protected reactor.core.publisher.Mono<org.elasticsearch.index.reindex.BulkByScrollResponse> doDeleteBy(Query query, Class<?> entityType, IndexCoordinates index)
    • doDelete

      protected reactor.core.publisher.Mono<String> doDelete(org.elasticsearch.action.delete.DeleteRequest request)
      Customization hook on the actual execution result Publisher.
      Parameters:
      request - the already prepared DeleteRequest ready to be executed.
      Returns:
      a Mono emitting the result of the operation.
    • doDeleteBy

      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.
      Parameters:
      request - the already prepared DeleteByQueryRequest ready to be executed.
      Returns:
      a Mono emitting the result of the operation.
    • prepareDeleteRequest

      protected org.elasticsearch.action.delete.DeleteRequest prepareDeleteRequest(org.elasticsearch.action.delete.DeleteRequest request)
      Customization hook to modify a generated DeleteRequest prior to its execution. E.g. by setting the refresh policy if applicable.
      Parameters:
      request - the generated DeleteRequest.
      Returns:
      never null.
    • prepareDeleteByRequest

      protected org.elasticsearch.index.reindex.DeleteByQueryRequest prepareDeleteByRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest request)
      Customization hook to modify a generated DeleteByQueryRequest prior to its execution. E.g. by setting the refresh policy if applicable.
      Parameters:
      request - the generated DeleteByQueryRequest.
      Returns:
      never null.
    • prepareIndexRequest

      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. E.g. by setting the refresh policy if applicable.
      Parameters:
      source - the source object the IndexRequest was derived from.
      request - the generated IndexRequest.
      Returns:
      never null.
    • prepareWriteRequest

      protected <R extends org.elasticsearch.action.support.WriteRequest<R>> R prepareWriteRequest(R request)
      Preprocess the write request before it is sent to the server, e.g. by setting the refresh policy if applicable.
      Type Parameters:
      R -
      Parameters:
      request - must not be null.
      Returns:
      the processed WriteRequest.
    • searchForPage

      public <T> reactor.core.publisher.Mono<SearchPage<T>> searchForPage(Query query, Class<?> entityType, Class<T> resultType)
      Description copied from interface: ReactiveSearchOperations
      Search the index for entities matching the given query.
      Specified by:
      searchForPage in interface ReactiveSearchOperations
      Overrides:
      searchForPage in class AbstractReactiveElasticsearchTemplate
      Parameters:
      query - must not be null.
      entityType - must not be null.
      resultType - the projection result type.
      Returns:
      a Mono emitting matching entities in a SearchHits.
    • searchForPage

      public <T> reactor.core.publisher.Mono<SearchPage<T>> searchForPage(Query query, Class<?> entityType, Class<T> resultType, IndexCoordinates index)
      Description copied from interface: ReactiveSearchOperations
      Search the index for entities matching the given query.
      Specified by:
      searchForPage in interface ReactiveSearchOperations
      Overrides:
      searchForPage in class AbstractReactiveElasticsearchTemplate
      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 Mono emitting matching entities in a SearchHits.
    • doFind

      protected reactor.core.publisher.Flux<SearchDocument> doFind(Query query, Class<?> clazz, IndexCoordinates index)
      Specified by:
      doFind in class AbstractReactiveElasticsearchTemplate
    • doFindForResponse

      protected <T> reactor.core.publisher.Mono<SearchDocumentResponse> doFindForResponse(Query query, Class<?> clazz, IndexCoordinates index)
      Specified by:
      doFindForResponse in class AbstractReactiveElasticsearchTemplate
    • aggregate

      public reactor.core.publisher.Flux<AggregationContainer<?>> aggregate(Query query, Class<?> entityType, IndexCoordinates index)
      Description copied from interface: ReactiveSearchOperations
      Perform an aggregation specified by the given query.
      Parameters:
      query - must not be null.
      entityType - must not be null.
      index - the target index, must not be null
      Returns:
      a Flux emitting matching aggregations one by one.
    • doAggregate

      protected reactor.core.publisher.Flux<AggregationContainer<?>> doAggregate(org.elasticsearch.action.search.SearchRequest request)
      Customization hook on the actual execution result Publisher.
      Parameters:
      request - the already prepared SearchRequest ready to be executed.
      Returns:
      a Flux emitting the result of the operation.
    • suggest

      @Deprecated public reactor.core.publisher.Flux<org.elasticsearch.search.suggest.Suggest> suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, Class<?> entityType)
      Deprecated.
      Description copied from interface: ReactiveSearchOperations
      Does a suggest query
      Parameters:
      suggestion - the query
      entityType - must not be null.
      Returns:
      the suggest response (Elasticsearch library classes)
    • suggest

      @Deprecated public reactor.core.publisher.Flux<org.elasticsearch.search.suggest.Suggest> suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, IndexCoordinates index)
      Deprecated.
      Description copied from interface: ReactiveSearchOperations
      Does a suggest query
      Parameters:
      suggestion - the query
      index - the index to run the query against
      Returns:
      the suggest response (Elasticsearch library classes)
    • doCount

      protected reactor.core.publisher.Mono<Long> doCount(Query query, Class<?> entityType, IndexCoordinates index)
      Specified by:
      doCount in class AbstractReactiveElasticsearchTemplate
    • doFind

      protected reactor.core.publisher.Flux<SearchDocument> doFind(org.elasticsearch.action.search.SearchRequest request)
      Customization hook on the actual execution result Publisher.
      Parameters:
      request - the already prepared SearchRequest ready to be executed.
      Returns:
      a Flux emitting the result of the operation converted to SearchDocuments.
    • doFindForResponse

      protected <T> reactor.core.publisher.Mono<SearchDocumentResponse> doFindForResponse(org.elasticsearch.action.search.SearchRequest request, SearchDocumentResponse.EntityCreator<T> entityCreator)
      Customization hook on the actual execution result Mono.
      Parameters:
      request - the already prepared SearchRequest ready to be executed.
      entityCreator -
      Returns:
      a Mono emitting the result of the operation converted to s SearchDocumentResponse.
    • doCount

      protected reactor.core.publisher.Mono<Long> doCount(org.elasticsearch.action.search.SearchRequest request)
      Customization hook on the actual execution result Publisher.
      Parameters:
      request - the already prepared SearchRequest ready to be executed.
      Returns:
      a Mono emitting the result of the operation.
    • doScroll

      protected reactor.core.publisher.Flux<SearchDocument> doScroll(org.elasticsearch.action.search.SearchRequest request)
      Customization hook on the actual execution result Publisher.
      Parameters:
      request - the already prepared SearchRequest ready to be executed.
      Returns:
      a Flux emitting the result of the operation converted to SearchDocuments.
    • prepareSearchRequest

      protected org.elasticsearch.action.search.SearchRequest prepareSearchRequest(org.elasticsearch.action.search.SearchRequest request, boolean useScroll)
      Customization hook to modify a generated SearchRequest prior to its execution. E.g. by setting the indices options if applicable.
      Parameters:
      request - the generated SearchRequest.
      useScroll -
      Returns:
      never null.
    • getClusterVersion

      protected reactor.core.publisher.Mono<String> getClusterVersion()
      Specified by:
      getClusterVersion in class AbstractReactiveElasticsearchTemplate
    • getVendor

      protected reactor.core.publisher.Mono<String> getVendor()
      Specified by:
      getVendor in class AbstractReactiveElasticsearchTemplate
      Returns:
      the vendor name of the used cluster and client library
      Since:
      4.3
    • getRuntimeLibraryVersion

      protected reactor.core.publisher.Mono<String> getRuntimeLibraryVersion()
      Specified by:
      getRuntimeLibraryVersion in class AbstractReactiveElasticsearchTemplate
      Returns:
      the version of the used client runtime library.
      Since:
      4.3
    • matchAllQuery

      public Query matchAllQuery()
      Description copied from interface: ReactiveSearchOperations
      Creates a Query to find all documents. Must be implemented by the concrete implementations to provide an appropriate query using the respective client.
      Returns:
      a query to find all documents
    • idsQuery

      public Query idsQuery(List<String> ids)
      Description copied from interface: ReactiveSearchOperations
      Creates a Query to find get all documents with given ids. Must be implemented by the concrete implementations to provide an appropriate query using the respective client.
      Parameters:
      ids - the list of ids must not be null
      Returns:
      query returning the documents with the given ids
    • execute

      public <T> org.reactivestreams.Publisher<T> execute(ReactiveElasticsearchOperations.ClientCallback<org.reactivestreams.Publisher<T>> callback)
      Description copied from interface: ReactiveElasticsearchOperations
      Execute within a ReactiveElasticsearchOperations.ClientCallback managing resources and translating errors.
      Type Parameters:
      T - the type the Publisher emits
      Parameters:
      callback - must not be null.
      Returns:
      the Publisher emitting results.
    • executeWithIndicesClient

      public <T> org.reactivestreams.Publisher<T> executeWithIndicesClient(ReactiveElasticsearchOperations.IndicesClientCallback<org.reactivestreams.Publisher<T>> callback)
      Description copied from interface: ReactiveElasticsearchOperations
      Execute within a ReactiveElasticsearchOperations.IndicesClientCallback managing resources and translating errors.
      Type Parameters:
      T - the type the Publisher emits
      Parameters:
      callback - must not be null.
      Returns:
      the Publisher emitting results.
    • executeWithClusterClient

      public <T> org.reactivestreams.Publisher<T> executeWithClusterClient(ReactiveElasticsearchOperations.ClusterClientCallback<org.reactivestreams.Publisher<T>> callback)
      Description copied from interface: ReactiveElasticsearchOperations
      Execute within a ReactiveElasticsearchOperations.ClusterClientCallback managing resources and translating errors.
      Type Parameters:
      T - the type the Publisher emits
      Parameters:
      callback - must not be null.
      Returns:
      the Publisher emitting results.
    • indexOps

      public ReactiveIndexOperations indexOps(IndexCoordinates index)
      Description copied from interface: ReactiveElasticsearchOperations
      Creates a ReactiveIndexOperations that is bound to the given index
      Parameters:
      index - IndexCoordinates specifying the index
      Returns:
      ReactiveIndexOperations implementation
    • indexOps

      public ReactiveIndexOperations indexOps(Class<?> clazz)
      Description copied from interface: ReactiveElasticsearchOperations
      Creates a ReactiveIndexOperations that is bound to the given class
      Parameters:
      clazz - the entity clazz specifiying the index information
      Returns:
      ReactiveIndexOperations implementation
    • cluster

      public ReactiveClusterOperations cluster()
      Description copied from interface: ReactiveElasticsearchOperations
      return a ReactiveClusterOperations instance that uses the same client communication setup as this ElasticsearchOperations instance.
      Returns:
      ClusterOperations implementation
    • getClient

      protected ReactiveElasticsearchClient getClient()
      Obtain the ReactiveElasticsearchClient to operate upon.
      Returns:
      never null.
    • getIndicesClient

      protected ReactiveElasticsearchClient.Indices getIndicesClient()
      Obtain the ReactiveElasticsearchClient.Indices to operate upon.
      Returns:
      never null.
    • getClusterClient

      protected ReactiveElasticsearchClient.Cluster getClusterClient()
      Obtain the ReactiveElasticsearchClient.Cluster to operate upon.
      Returns:
      never null.