Interface SearchOperations

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

public interface SearchOperations
The operations for the Elasticsearch Document APIs.
Since:
4.0
Author:
Peter-Josef Meisch, Sascha Woo
  • Method Details

    • count

      default long count(Query query, IndexCoordinates index)
      Return number of elements found by given query.
      Parameters:
      query - the query to execute
      index - the index to run the query against
      Returns:
      count
    • count

      long count(Query query, Class<?> clazz)
      return number of elements found by given query
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping and index name extraction
      Returns:
      count
    • count

      long count(Query query, @Nullable Class<?> clazz, IndexCoordinates index)
      return number of elements found by given query
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping
      index - the index to run the query against
      Returns:
      count
    • suggest

      @Deprecated default org.elasticsearch.action.search.SearchResponse suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, Class<?> clazz)
      Does a suggest query
      Parameters:
      suggestion - the query
      clazz - the entity class
      Returns:
      the suggest response
      Since:
      4.1
    • suggest

      @Deprecated default org.elasticsearch.action.search.SearchResponse suggest(org.elasticsearch.search.suggest.SuggestBuilder suggestion, IndexCoordinates index)
      Does a suggest query
      Parameters:
      suggestion - the query
      index - the index to run the query against
      Returns:
      the suggest response
    • searchOne

      @Nullable default <T> SearchHit<T> searchOne(Query query, Class<T> clazz)
      Execute the query against elasticsearch and return the first returned object.
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping and indexname extraction
      Returns:
      the first found object
    • searchOne

      @Nullable default <T> SearchHit<T> searchOne(Query query, Class<T> clazz, IndexCoordinates index)
      Execute the query against elasticsearch and return the first returned object.
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping
      index - the index to run the query against
      Returns:
      the first found object
    • multiSearch

      <T> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<T> clazz)
      Execute the multi search query against elasticsearch and return result as List of SearchHits.
      Type Parameters:
      T - element return type
      Parameters:
      queries - the queries to execute
      clazz - the entity clazz
      Returns:
      list of SearchHits
      Since:
      4.1
    • multiSearch

      <T> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<T> clazz, IndexCoordinates index)
      Execute the multi search query against elasticsearch and return result as List of SearchHits.
      Type Parameters:
      T - element return type
      Parameters:
      queries - the queries to execute
      clazz - the entity clazz used for property mapping
      index - the index to run the query against
      Returns:
      list of SearchHits
    • multiSearch

      List<SearchHits<?>> multiSearch(List<? extends Query> queries, List<Class<?>> classes)
      Execute the multi search query against elasticsearch and return result as List of SearchHits.
      Parameters:
      queries - the queries to execute
      classes - the entity classes
      Returns:
      list of SearchHits
      Since:
      4.1
    • multiSearch

      List<SearchHits<?>> multiSearch(List<? extends Query> queries, List<Class<?>> classes, IndexCoordinates index)
      Execute the multi search query against elasticsearch and return result as List of SearchHits.
      Parameters:
      queries - the queries to execute
      classes - the entity classes used for property mapping
      index - the index to run the query against
      Returns:
      list of SearchHits
    • search

      <T> SearchHits<T> search(Query query, Class<T> clazz)
      Execute the criteria query against elasticsearch and return result as SearchHits
      Type Parameters:
      T - element return type
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping and index name extraction
      Returns:
      SearchHits containing the list of found objects
    • search

      <T> SearchHits<T> search(Query query, Class<T> clazz, IndexCoordinates index)
      Execute the criteria query against elasticsearch and return result as SearchHits
      Type Parameters:
      T - element return type
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping
      index - the index to run the query against
      Returns:
      SearchHits containing the list of found objects
    • search

      <T> SearchHits<T> search(MoreLikeThisQuery query, Class<T> clazz)
      more like this query to search for documents that are "like" a specific document.
      Type Parameters:
      T - element return type
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping and index name extraction
      Returns:
      SearchHits containing the list of found objects
    • search

      <T> SearchHits<T> search(MoreLikeThisQuery query, Class<T> clazz, IndexCoordinates index)
      more like this query to search for documents that are "like" a specific document.
      Type Parameters:
      T - element return type
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping
      index - the index to run the query against
      Returns:
      SearchHits containing the list of found objects
    • searchForStream

      <T> SearchHitsIterator<T> searchForStream(Query query, Class<T> clazz)
      Executes the given Query against elasticsearch and return result as SearchHitsIterator.
      Type Parameters:
      T - element return type
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping and index name extraction
      Returns:
      a SearchHitsIterator that wraps an Elasticsearch scroll context that needs to be closed. The try-with-resources construct should be used to ensure that the close method is invoked after the operations are completed.
    • searchForStream

      <T> SearchHitsIterator<T> searchForStream(Query query, Class<T> clazz, IndexCoordinates index)
      Executes the given Query against elasticsearch and return result as SearchHitsIterator.
      Type Parameters:
      T - element return type
      Parameters:
      query - the query to execute
      clazz - the entity clazz used for property mapping
      index - the index to run the query against
      Returns:
      a SearchHitsIterator that wraps an Elasticsearch scroll context that needs to be closed. The try-with-resources construct should be used to ensure that the close method is invoked after the operations are completed.
    • matchAllQuery

      Query matchAllQuery()
      Creates a Query to get 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
      Since:
      4.3
    • idsQuery

      Query idsQuery(List<String> ids)
      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
      Since:
      4.3