All Known Implementing Classes:
BaseQuery, CriteriaQuery, NativeQuery, SearchTemplateQuery, StringQuery

public interface Query
Query
Author:
Rizwan Idrees, Mohsin Husen, Mark Paluch, Alen Turkovic, Sascha Woo, Christoph Strobl, Farid Azaza, Peter-Josef Meisch, Peer Mueller, vdisk
  • Field Details

  • Method Details

    • findAll

      static Query findAll()
      Get a Query that matches all documents in the index.
      Returns:
      new instance of Query.
      Since:
      3.2
    • setPageable

      <T extends Query> T setPageable(Pageable pageable)
      restrict result to entries on given page. Corresponds to the 'start' and 'rows' parameter in elasticsearch
      Parameters:
      pageable -
      Returns:
    • getPageable

      Pageable getPageable()
      Get page settings if defined
      Returns:
    • addSort

      <T extends Query> T addSort(@Nullable Sort sort)
      Add Sort to query
      Parameters:
      sort -
      Returns:
    • getSort

      @Nullable Sort getSort()
      Returns:
      null if not set
    • addFields

      void addFields(String... fields)
      Add fields to be added as part of search request
      Parameters:
      fields -
    • getFields

      List<String> getFields()
      Get fields to be returned as part of search request
      Returns:
      maybe empty, never null
    • setFields

      void setFields(List<String> fields)
      Set fields to be returned as part of search request
      Parameters:
      fields - must not be null
      Since:
      4.3
    • addStoredFields

      void addStoredFields(String... storedFields)
      Add stored fields to be added as part of search request
      Parameters:
      storedFields -
      Since:
      4.4
    • getStoredFields

      @Nullable List<String> getStoredFields()
      Get stored fields to be returned as part of search request
      Returns:
      null if not set
      Since:
      4.4
    • setStoredFields

      void setStoredFields(@Nullable List<String> storedFields)
      Set stored fields to be returned as part of search request
      Parameters:
      storedFields -
      Since:
      4.4
    • addSourceFilter

      void addSourceFilter(SourceFilter sourceFilter)
      Add source filter to be added as part of search request
      Parameters:
      sourceFilter -
    • getSourceFilter

      @Nullable SourceFilter getSourceFilter()
      Get SourceFilter to be returned to get include and exclude source fields as part of search request.
      Returns:
      SourceFilter
    • getMinScore

      float getMinScore()
      Get minimum score
      Returns:
    • getTrackScores

      boolean getTrackScores()
      Get if scores will be computed and tracked, regardless of whether sorting on a field. Defaults to false.
      Returns:
      Since:
      3.1
    • getIds

      Returns:
      Get ids set on this query.
    • getIdsWithRouting

      List<Query.IdWithRouting> getIdsWithRouting()
      Returns:
      Ids with routing values used in a multi-get request.
      Since:
      4.3
      See Also:
    • multiGetQueryWithRouting

      static Query multiGetQueryWithRouting(List<Query.IdWithRouting> idsWithRouting)
      Utility method to get a query for a multiget request
      Parameters:
      idsWithRouting - Ids with routing values used in a multi-get request.
      Returns:
      Query instance
    • multiGetQuery

      static Query multiGetQuery(Collection<String> ids)
      Utility method to get a query for a multiget request
      Parameters:
      ids - Ids used in a multi-get request.
      Returns:
      Query instance
    • getRoute

      @Nullable String getRoute()
      Get route
      Returns:
    • getSearchType

      @Nullable Query.SearchType getSearchType()
      Type of search
      Returns:
    • getIndicesOptions

      @Nullable IndicesOptions getIndicesOptions()
      Get indices options
      Returns:
      null if not set
    • getPreference

      @Nullable String getPreference()
      Get preference
      Returns:
      Since:
      3.2
    • setPreference

      void setPreference(String preference)
      Add preference filter to be added as part of search request
      Parameters:
      preference -
      Since:
      3.2
    • isLimiting

      default boolean isLimiting()
      Returns:
      true if the query has a limit on the max number of results.
      Since:
      4.0
    • getMaxResults

      @Nullable default Integer getMaxResults()
      return the max of results. Must not return null when isLimiting() returns true.
      Since:
      4.0
    • setHighlightQuery

      void setHighlightQuery(HighlightQuery highlightQuery)
      Sets the HighlightQuery.
      Parameters:
      highlightQuery - the query to set
      Since:
      4.0
    • getHighlightQuery

      default Optional<HighlightQuery> getHighlightQuery()
      Returns:
      the optional set HighlightQuery.
      Since:
      4.0
    • setTrackTotalHits

      void setTrackTotalHits(@Nullable Boolean trackTotalHits)
      Sets the flag whether to set the Track_total_hits parameter on queries
      Parameters:
      trackTotalHits - the value to set.
      Since:
      4.0
    • getTrackTotalHits

      @Nullable Boolean getTrackTotalHits()
      Sets the flag whether to set the Track_total_hits parameter on queries
      Returns:
      the set value.
      Since:
      4.0
    • setTrackTotalHitsUpTo

      void setTrackTotalHitsUpTo(@Nullable Integer trackTotalHitsUpTo)
      Sets the maximum value up to which total hits are tracked. Only relevant if #getTrackTotalHits is null
      Parameters:
      trackTotalHitsUpTo - max limit for trackTotalHits
      Since:
      4.1
    • getTrackTotalHitsUpTo

      @Nullable Integer getTrackTotalHitsUpTo()
      Gets the maximum value up to which total hits are tracked. Only relevant if #getTrackTotalHits is null
      Returns:
      max limit for trackTotalHits
      Since:
      4.1
    • getScrollTime

      @Nullable Duration getScrollTime()
      For queries that are used in delete request, these are internally handled by Elasticsearch as scroll/bulk delete queries. Must not return null when hasScrollTime() returns true.
      Returns:
      the scrolltime settings
      Since:
      4.0
    • setScrollTime

      void setScrollTime(@Nullable Duration scrollTime)
      For queries that are used in delete request, these are internally handled by Elasticsearch as scroll/bulk delete queries.
      Parameters:
      scrollTime - the scrolltime settings
      Since:
      4.0
    • hasScrollTime

      default boolean hasScrollTime()
      Returns:
      true if a scroll time is set.
      Since:
      4.0
    • getTimeout

      @Nullable Duration getTimeout()
      Get the query timeout.
      Returns:
      null if not set
      Since:
      4.2
    • getExplain

      default boolean getExplain()
      Returns:
      true when the query has the explain parameter set, defaults to false
      Since:
      4.2
    • setSearchAfter

      void setSearchAfter(@Nullable List<Object> searchAfter)
      Sets the setSearchAfter objects for this query.
      Parameters:
      searchAfter - the setSearchAfter objects. These are obtained with SearchHit.getSortValues() from a search result.
      Since:
      4.2
    • getSearchAfter

      @Nullable List<Object> getSearchAfter()
      Returns:
      the search_after objects.
      Since:
      4.2
    • addRescorerQuery

      void addRescorerQuery(RescorerQuery rescorerQuery)
      Parameters:
      rescorerQuery - the query to add to the list of rescorer queries, must not be null
      Since:
      4.2
    • setRescorerQueries

      void setRescorerQueries(List<RescorerQuery> rescorerQueryList)
      Sets the RescorerQuery.
      Parameters:
      rescorerQueryList - list of rescorer queries set, must not be null.
      Since:
      4.2
    • getRescorerQueries

      default List<RescorerQuery> getRescorerQueries()
      get the list of RescorerQuerys
      Since:
      4.2
    • setRequestCache

      void setRequestCache(@Nullable Boolean value)
      sets the request_cache value for the query.
      Parameters:
      value - new value
      Since:
      4.3
    • getRequestCache

      @Nullable Boolean getRequestCache()
      Returns:
      the request_cache value for this query.
      Since:
      4.3
    • addRuntimeField

      void addRuntimeField(RuntimeField runtimeField)
      Adds a runtime field to the query.
      Parameters:
      runtimeField - the runtime field definition, must not be null
      Since:
      4.3
    • getRuntimeFields

      List<RuntimeField> getRuntimeFields()
      Returns:
      the runtime fields for this query. May be empty but not null
      Since:
      4.3
    • getIndicesBoost

      @Nullable List<IndexBoost> getIndicesBoost()
      Since:
      4.4
    • getPointInTime

      @Nullable default Query.PointInTime getPointInTime()
      Returns:
      the point in time id to use in the query
      Since:
      5.0
    • getReactiveBatchSize

      default Integer getReactiveBatchSize()
      returns the number of documents that are requested when the reactive code does a batched search operation. This is the case when a query has no limit and no Pageable set.
      Returns:
      the batch size, defaults to 500 in BaseQuery
      Since:
      5.1
    • getAllowNoIndices

      @Nullable Boolean getAllowNoIndices()
      Since:
      5.1
    • getExpandWildcards

      Since:
      5.1
    • getDocValueFields

      List<DocValueField> getDocValueFields()
      Returns:
      a possible empty list of docvalue_field values to be set on the query.
      Since:
      5.1
    • getScriptedFields

      List<ScriptedField> getScriptedFields()
      Returns:
      the list of scripted fields for the query
      Since:
      5.1