Interface DocumentOperations

All Known Subinterfaces:
ElasticsearchOperations
All Known Implementing Classes:
AbstractElasticsearchTemplate, ElasticsearchRestTemplate, ElasticsearchTemplate

public interface DocumentOperations
The operations for the Elasticsearch Document APIs.
Since:
4.0
Author:
Peter-Josef Meisch, Farid Faoudi, Sijia Liu
  • Method Details

    • save

      <T> T save(T entity)
      Saves an entity to the index specified in the entity's Document annotation
      Type Parameters:
      T - the entity type
      Parameters:
      entity - the entity to save, must not be null
      Returns:
      the saved entity
    • save

      <T> T save(T entity, IndexCoordinates index)
      Saves an entity to the index specified in the entity's Document annotation
      Type Parameters:
      T - the entity type
      Parameters:
      entity - the entity to save, must not be null
      index - the index to save the entity in, must not be null
      Returns:
      the saved entity
    • save

      <T> Iterable<T> save(Iterable<T> entities)
      saves the given entities to the index retrieved from the entities' Document annotation
      Type Parameters:
      T - the entity type
      Parameters:
      entities - must not be null
      Returns:
      the saved entites
    • save

      <T> Iterable<T> save(Iterable<T> entities, IndexCoordinates index)
      saves the given entities to the given index
      Type Parameters:
      T - the entity type
      Parameters:
      entities - must not be null
      index - the index to save the entities in, must not be null
      Returns:
      the saved entities
    • save

      <T> Iterable<T> save(T... entities)
      saves the given entities to the index retrieved from the entities' Document annotation
      Type Parameters:
      T - the entity type
      Parameters:
      entities - must not be null
      Returns:
      the saved entities as Iterable
    • index

      String index(IndexQuery query, IndexCoordinates index)
      Index an object. Will do save or update.
      Parameters:
      query - the query defining the object
      index - the index where the object is stored.
      Returns:
      returns the document id
    • get

      @Nullable <T> T get(String id, Class<T> clazz)
      Retrieves an object from the index specified in the entity's Document annotation.
      Type Parameters:
      T - the entity type
      Parameters:
      id - the id of the object
      clazz - the entity class,
      Returns:
      the entity
    • get

      @Nullable <T> T get(String id, Class<T> clazz, IndexCoordinates index)
      Retrieves an object from the index specified in the entity's Document annotation.
      Parameters:
      id - the id of the object
      clazz - the entity class,
      index - the index from which the object is read.
      Returns:
      the entity
    • multiGet

      <T> List<MultiGetItem<T>> multiGet(Query query, Class<T> clazz)
      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
      Returns:
      list of MultiGetItems
      Since:
      4.1
      See Also:
    • multiGet

      <T> List<MultiGetItem<T>> multiGet(Query query, Class<T> clazz, IndexCoordinates index)
      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:
      list of MultiGetItems
      See Also:
    • exists

      boolean exists(String id, Class<?> clazz)
      Check if an entity with given id exists.
      Parameters:
      id - the _id of the document to look for.
      clazz - the domain type used.
      Returns:
      true if a matching document exists, false otherwise.
    • exists

      boolean exists(String id, IndexCoordinates index)
      Check if an entity with given id exists.
      Parameters:
      id - the _id of the document to look for.
      index - the target index, must not be null
      Returns:
      true if a matching document exists, false otherwise.
    • bulkIndex

      default List<IndexedObjectInformation> bulkIndex(List<IndexQuery> queries, Class<?> clazz)
      Bulk index all objects. Will do save or update.
      Parameters:
      queries - the queries to execute in bulk
      clazz - the entity class
      Returns:
      the information about the indexed objects
      Throws:
      BulkFailureException - with information about the failed operation
      Since:
      4.1
    • bulkIndex

      default List<IndexedObjectInformation> bulkIndex(List<IndexQuery> queries, IndexCoordinates index)
      Bulk index all objects. Will do save or update.
      Parameters:
      queries - the queries to execute in bulk
      Returns:
      the information about of the indexed objects
      Throws:
      BulkFailureException - with information about the failed operation
    • bulkIndex

      List<IndexedObjectInformation> bulkIndex(List<IndexQuery> queries, BulkOptions bulkOptions, Class<?> clazz)
      Bulk index all objects. Will do save or update.
      Parameters:
      queries - the queries to execute in bulk
      bulkOptions - options to be added to the bulk request
      clazz - the entity class
      Returns:
      the information about of the indexed objects
      Throws:
      BulkFailureException - with information about the failed operation
      Since:
      4.1
    • bulkIndex

      List<IndexedObjectInformation> bulkIndex(List<IndexQuery> queries, BulkOptions bulkOptions, IndexCoordinates index)
      Bulk index all objects. Will do save or update.
      Parameters:
      queries - the queries to execute in bulk
      bulkOptions - options to be added to the bulk request
      Returns:
      the information about of the indexed objects
      Throws:
      BulkFailureException - with information about the failed operation
    • bulkUpdate

      default void bulkUpdate(List<UpdateQuery> queries, IndexCoordinates index)
      Bulk update all objects. Will do update.
      Parameters:
      queries - the queries to execute in bulk
      Throws:
      BulkFailureException - with information about the failed operation
    • bulkUpdate

      void bulkUpdate(List<UpdateQuery> queries, Class<?> clazz)
      Bulk update all objects. Will do update.
      Parameters:
      clazz - the entity class
      queries - the queries to execute in bulk
      Throws:
      BulkFailureException - with information about the failed operation
      Since:
      4.1
    • bulkUpdate

      void bulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index)
      Bulk update all objects. Will do update.
      Parameters:
      queries - the queries to execute in bulk
      bulkOptions - options to be added to the bulk request
      Throws:
      BulkFailureException - with information about the failed operation
    • delete

      String delete(String id, IndexCoordinates index)
      Delete the one object with provided id.
      Parameters:
      id - the document to delete
      index - the index from which to delete
      Returns:
      documentId of the document deleted
    • delete

      @Deprecated String delete(String id, @Nullable String routing, IndexCoordinates index)
      Delete the one object with provided id.
      Parameters:
      id - the document to delete
      routing - the optional routing for the document to be deleted
      index - the index from which to delete
      Returns:
      documentId of the document deleted
      Since:
      4.1
    • delete

      String delete(String id, Class<?> entityType)
      Delete the one object with provided id.
      Parameters:
      id - the document ot delete
      entityType - must not be null.
      Returns:
      documentId of the document deleted
    • delete

      String delete(Object entity)
      Deletes the given entity
      Parameters:
      entity - the entity to delete
      Returns:
      documentId of the document deleted
    • delete

      String delete(Object entity, IndexCoordinates index)
      Deletes the given entity
      Parameters:
      entity - the entity to delete
      index - the index from which to delete
      Returns:
      documentId of the document deleted
    • delete

      ByQueryResponse delete(Query query, Class<?> clazz)
      Delete all records matching the query.
      Parameters:
      query - query defining the objects
      clazz - The entity class, must be annotated with Document
      Returns:
      response with detailed information
      Since:
      4.1
    • delete

      ByQueryResponse delete(Query query, Class<?> clazz, IndexCoordinates index)
      Delete all records matching the query.
      Parameters:
      query - query defining the objects
      clazz - The entity class, must be annotated with Document
      index - the index from which to delete
      Returns:
      response with detailed information
    • update

      UpdateResponse update(UpdateQuery updateQuery, IndexCoordinates index)
      Partial update of the document.
      Parameters:
      updateQuery - query defining the update
      index - the index where to update the records
      Returns:
      the update response
    • updateByQuery

      ByQueryResponse updateByQuery(UpdateQuery updateQuery, IndexCoordinates index)
      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:
      the update response
      Since:
      4.2
    • reindex

      ReindexResponse reindex(ReindexRequest reindexRequest)
      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:
      reindexRequest - reindex request parameters
      Returns:
      the reindex response
      Since:
      4.4
    • submitReindex

      String submitReindex(ReindexRequest reindexRequest)
      Submits a reindex task. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
      Parameters:
      reindexRequest - reindex request parameters
      Returns:
      the task id
      Since:
      4.4