java.lang.Object
org.springframework.data.elasticsearch.core.query.BaseQuery
All Implemented Interfaces:
Query
Direct Known Subclasses:
CriteriaQuery, NativeQuery, SearchTemplateQuery, StringQuery

public class BaseQuery extends Object implements Query
BaseQuery
Author:
Rizwan Idrees, Mohsin Husen, Mark Paluch, Alen Turkovic, Sascha Woo, Farid Azaza, Peter-Josef Meisch, Peer Mueller, vdisk
  • Field Details

  • Constructor Details

    • BaseQuery

      public BaseQuery()
    • BaseQuery

      public BaseQuery(BaseQueryBuilder<Q,B> builder)
  • Method Details

    • setSort

      public void setSort(@Nullable Sort sort)
      Since:
      5.1
    • getSort

      @Nullable public Sort getSort()
      Specified by:
      getSort in interface Query
      Returns:
      null if not set
    • getPageable

      public Pageable getPageable()
      Description copied from interface: Query
      Get page settings if defined
      Specified by:
      getPageable in interface Query
      Returns:
    • setPageable

      public final <T extends Query> T setPageable(Pageable pageable)
      Description copied from interface: Query
      restrict result to entries on given page. Corresponds to the 'start' and 'rows' parameter in elasticsearch
      Specified by:
      setPageable in interface Query
      Returns:
    • addFields

      public void addFields(String... fields)
      Description copied from interface: Query
      Add fields to be added as part of search request
      Specified by:
      addFields in interface Query
    • getFields

      public List<String> getFields()
      Description copied from interface: Query
      Get fields to be returned as part of search request
      Specified by:
      getFields in interface Query
      Returns:
      maybe empty, never null
    • setFields

      public void setFields(List<String> fields)
      Description copied from interface: Query
      Set fields to be returned as part of search request
      Specified by:
      setFields in interface Query
      Parameters:
      fields - must not be null
    • addStoredFields

      public void addStoredFields(String... storedFields)
      Description copied from interface: Query
      Add stored fields to be added as part of search request
      Specified by:
      addStoredFields in interface Query
    • getStoredFields

      @Nullable public List<String> getStoredFields()
      Description copied from interface: Query
      Get stored fields to be returned as part of search request
      Specified by:
      getStoredFields in interface Query
      Returns:
      null if not set
    • setStoredFields

      public void setStoredFields(@Nullable List<String> storedFields)
      Description copied from interface: Query
      Set stored fields to be returned as part of search request
      Specified by:
      setStoredFields in interface Query
    • addSourceFilter

      public void addSourceFilter(SourceFilter sourceFilter)
      Description copied from interface: Query
      Add source filter to be added as part of search request
      Specified by:
      addSourceFilter in interface Query
    • getSourceFilter

      @Nullable public SourceFilter getSourceFilter()
      Description copied from interface: Query
      Get SourceFilter to be returned to get include and exclude source fields as part of search request.
      Specified by:
      getSourceFilter in interface Query
      Returns:
      SourceFilter
    • addSort

      public final <T extends Query> T addSort(@Nullable Sort sort)
      Description copied from interface: Query
      Add Sort to query
      Specified by:
      addSort in interface Query
      Returns:
    • getMinScore

      public float getMinScore()
      Description copied from interface: Query
      Get minimum score
      Specified by:
      getMinScore in interface Query
      Returns:
    • setMinScore

      public void setMinScore(float minScore)
    • setIds

      public void setIds(@Nullable Collection<String> ids)
      Set Ids for a multi-get request run with this query. Not used in any other searches.
      Parameters:
      ids - list of id values
    • getIds

      @Nullable public Collection<String> getIds()
      Specified by:
      getIds in interface Query
      Returns:
      Get ids set on this query.
    • getIdsWithRouting

      public List<Query.IdWithRouting> getIdsWithRouting()
      Specified by:
      getIdsWithRouting in interface Query
      Returns:
      Ids with routing values used in a multi-get request.
      See Also:
    • setIdsWithRouting

      public void setIdsWithRouting(List<Query.IdWithRouting> idsWithRouting)
      Set Ids with routing values for a multi-get request run with this query. Not used in any other searches.
      Parameters:
      idsWithRouting - list of id values, must not be null
      Since:
      4.3
    • getRoute

      @Nullable public String getRoute()
      Description copied from interface: Query
      Get route
      Specified by:
      getRoute in interface Query
      Returns:
    • setRoute

      public void setRoute(String route)
    • setSearchType

      public void setSearchType(@Nullable Query.SearchType searchType)
    • getSearchType

      @Nullable public Query.SearchType getSearchType()
      Description copied from interface: Query
      Type of search
      Specified by:
      getSearchType in interface Query
      Returns:
    • getIndicesOptions

      @Nullable public IndicesOptions getIndicesOptions()
      Description copied from interface: Query
      Get indices options
      Specified by:
      getIndicesOptions in interface Query
      Returns:
      null if not set
    • setIndicesOptions

      public void setIndicesOptions(IndicesOptions indicesOptions)
    • getTrackScores

      public boolean getTrackScores()
      Description copied from interface: Query
      Get if scores will be computed and tracked, regardless of whether sorting on a field. Defaults to false.
      Specified by:
      getTrackScores in interface Query
      Returns:
    • setTrackScores

      public void setTrackScores(boolean trackScores)
      Configures whether to track scores.
      Since:
      3.1
    • getPreference

      @Nullable public String getPreference()
      Description copied from interface: Query
      Get preference
      Specified by:
      getPreference in interface Query
      Returns:
    • setPreference

      public void setPreference(String preference)
      Description copied from interface: Query
      Add preference filter to be added as part of search request
      Specified by:
      setPreference in interface Query
    • isLimiting

      public boolean isLimiting()
      Specified by:
      isLimiting in interface Query
      Returns:
      true if the query has a limit on the max number of results.
    • getMaxResults

      @Nullable public Integer getMaxResults()
      Description copied from interface: Query
      return the max of results. Must not return null when Query.isLimiting() returns true.
      Specified by:
      getMaxResults in interface Query
    • setMaxResults

      public void setMaxResults(Integer maxResults)
    • setHighlightQuery

      public void setHighlightQuery(HighlightQuery highlightQuery)
      Description copied from interface: Query
      Sets the HighlightQuery.
      Specified by:
      setHighlightQuery in interface Query
      Parameters:
      highlightQuery - the query to set
    • getHighlightQuery

      public Optional<HighlightQuery> getHighlightQuery()
      Specified by:
      getHighlightQuery in interface Query
      Returns:
      the optional set HighlightQuery.
    • setTrackTotalHits

      public void setTrackTotalHits(@Nullable Boolean trackTotalHits)
      Description copied from interface: Query
      Sets the flag whether to set the Track_total_hits parameter on queries
      Specified by:
      setTrackTotalHits in interface Query
      Parameters:
      trackTotalHits - the value to set.
    • getTrackTotalHits

      @Nullable public Boolean getTrackTotalHits()
      Description copied from interface: Query
      Sets the flag whether to set the Track_total_hits parameter on queries
      Specified by:
      getTrackTotalHits in interface Query
      Returns:
      the set value.
    • setTrackTotalHitsUpTo

      public void setTrackTotalHitsUpTo(@Nullable Integer trackTotalHitsUpTo)
      Description copied from interface: Query
      Sets the maximum value up to which total hits are tracked. Only relevant if #getTrackTotalHits is null
      Specified by:
      setTrackTotalHitsUpTo in interface Query
      Parameters:
      trackTotalHitsUpTo - max limit for trackTotalHits
    • getTrackTotalHitsUpTo

      @Nullable public Integer getTrackTotalHitsUpTo()
      Description copied from interface: Query
      Gets the maximum value up to which total hits are tracked. Only relevant if #getTrackTotalHits is null
      Specified by:
      getTrackTotalHitsUpTo in interface Query
      Returns:
      max limit for trackTotalHits
    • getScrollTime

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

      public void setScrollTime(@Nullable Duration scrollTime)
      Description copied from interface: Query
      For queries that are used in delete request, these are internally handled by Elasticsearch as scroll/bulk delete queries.
      Specified by:
      setScrollTime in interface Query
      Parameters:
      scrollTime - the scrolltime settings
    • getTimeout

      @Nullable public Duration getTimeout()
      Description copied from interface: Query
      Get the query timeout.
      Specified by:
      getTimeout in interface Query
      Returns:
      null if not set
    • setTimeout

      public void setTimeout(@Nullable Duration timeout)
      set the query timeout
      Since:
      4.2
    • getExplain

      public boolean getExplain()
      Specified by:
      getExplain in interface Query
      Returns:
      true when the query has the explain parameter set, defaults to false
    • setExplain

      public void setExplain(boolean explain)
      Parameters:
      explain - the explain flag on the query.
    • setSearchAfter

      public void setSearchAfter(@Nullable List<Object> searchAfter)
      Description copied from interface: Query
      Sets the setSearchAfter objects for this query.
      Specified by:
      setSearchAfter in interface Query
      Parameters:
      searchAfter - the setSearchAfter objects. These are obtained with SearchHit.getSortValues() from a search result.
    • getSearchAfter

      @Nullable public List<Object> getSearchAfter()
      Specified by:
      getSearchAfter in interface Query
      Returns:
      the search_after objects.
    • addRescorerQuery

      public void addRescorerQuery(RescorerQuery rescorerQuery)
      Description copied from interface: Query
      Specified by:
      addRescorerQuery in interface Query
      Parameters:
      rescorerQuery - the query to add to the list of rescorer queries, must not be null
    • setRescorerQueries

      public void setRescorerQueries(List<RescorerQuery> rescorerQueryList)
      Description copied from interface: Query
      Sets the RescorerQuery.
      Specified by:
      setRescorerQueries in interface Query
      Parameters:
      rescorerQueryList - list of rescorer queries set, must not be null.
    • getRescorerQueries

      public List<RescorerQuery> getRescorerQueries()
      Description copied from interface: Query
      get the list of RescorerQuerys
      Specified by:
      getRescorerQueries in interface Query
    • setRequestCache

      public void setRequestCache(@Nullable Boolean value)
      Description copied from interface: Query
      sets the request_cache value for the query.
      Specified by:
      setRequestCache in interface Query
      Parameters:
      value - new value
    • getRequestCache

      @Nullable public Boolean getRequestCache()
      Specified by:
      getRequestCache in interface Query
      Returns:
      the request_cache value for this query.
    • addRuntimeField

      public void addRuntimeField(RuntimeField runtimeField)
      Description copied from interface: Query
      Adds a runtime field to the query.
      Specified by:
      addRuntimeField in interface Query
      Parameters:
      runtimeField - the runtime field definition, must not be null
    • getRuntimeFields

      public List<RuntimeField> getRuntimeFields()
      Specified by:
      getRuntimeFields in interface Query
      Returns:
      the runtime fields for this query. May be empty but not null
    • getIndicesBoost

      @Nullable public List<IndexBoost> getIndicesBoost()
      Specified by:
      getIndicesBoost in interface Query
    • getPointInTime

      @Nullable public Query.PointInTime getPointInTime()
      Specified by:
      getPointInTime in interface Query
      Returns:
      the point in time id to use in the query
      Since:
      5.0
    • setPointInTime

      public void setPointInTime(@Nullable Query.PointInTime pointInTime)
      Since:
      5.0
    • queryIsUpdatedByConverter

      public boolean queryIsUpdatedByConverter()
      used internally. Not considered part of the API.
      Since:
      5.0
    • setQueryIsUpdatedByConverter

      public void setQueryIsUpdatedByConverter(boolean queryIsUpdatedByConverter)
      used internally. Not considered part of the API.
      Since:
      5.0
    • getReactiveBatchSize

      public Integer getReactiveBatchSize()
      Description copied from interface: Query
      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.
      Specified by:
      getReactiveBatchSize in interface Query
      Returns:
      the batch size, defaults to 500 in BaseQuery
    • setReactiveBatchSize

      public void setReactiveBatchSize(Integer reactiveBatchSize)
      Since:
      5.1
    • getAllowNoIndices

      @Nullable public Boolean getAllowNoIndices()
      Specified by:
      getAllowNoIndices in interface Query
    • getExpandWildcards

      public EnumSet<IndicesOptions.WildcardStates> getExpandWildcards()
      Specified by:
      getExpandWildcards in interface Query
    • getDocValueFields

      public List<DocValueField> getDocValueFields()
      Specified by:
      getDocValueFields in interface Query
      Returns:
      a possible empty list of docvalue_field values to be set on the query.
      Since:
      5.1
    • setDocValueFields

      public void setDocValueFields(List<DocValueField> docValueFields)
      Since:
      5.1
    • addScriptedField

      public void addScriptedField(ScriptedField scriptedField)
      Since:
      5.2
    • getScriptedFields

      public List<ScriptedField> getScriptedFields()
      Specified by:
      getScriptedFields in interface Query
      Returns:
      the list of scripted fields for the query