Class SearchSourceBuilder

    • Field Detail

      • FROM_FIELD

        public static final ParseField FROM_FIELD
      • SIZE_FIELD

        public static final ParseField SIZE_FIELD
      • TIMEOUT_FIELD

        public static final ParseField TIMEOUT_FIELD
      • TERMINATE_AFTER_FIELD

        public static final ParseField TERMINATE_AFTER_FIELD
      • QUERY_FIELD

        public static final ParseField QUERY_FIELD
      • POST_FILTER_FIELD

        public static final ParseField POST_FILTER_FIELD
      • MIN_SCORE_FIELD

        public static final ParseField MIN_SCORE_FIELD
      • VERSION_FIELD

        public static final ParseField VERSION_FIELD
      • SEQ_NO_PRIMARY_TERM_FIELD

        public static final ParseField SEQ_NO_PRIMARY_TERM_FIELD
      • EXPLAIN_FIELD

        public static final ParseField EXPLAIN_FIELD
      • _SOURCE_FIELD

        public static final ParseField _SOURCE_FIELD
      • STORED_FIELDS_FIELD

        public static final ParseField STORED_FIELDS_FIELD
      • DOCVALUE_FIELDS_FIELD

        public static final ParseField DOCVALUE_FIELDS_FIELD
      • SCRIPT_FIELDS_FIELD

        public static final ParseField SCRIPT_FIELDS_FIELD
      • SCRIPT_FIELD

        public static final ParseField SCRIPT_FIELD
      • IGNORE_FAILURE_FIELD

        public static final ParseField IGNORE_FAILURE_FIELD
      • SORT_FIELD

        public static final ParseField SORT_FIELD
      • TRACK_SCORES_FIELD

        public static final ParseField TRACK_SCORES_FIELD
      • TRACK_TOTAL_HITS_FIELD

        public static final ParseField TRACK_TOTAL_HITS_FIELD
      • INDICES_BOOST_FIELD

        public static final ParseField INDICES_BOOST_FIELD
      • AGGREGATIONS_FIELD

        public static final ParseField AGGREGATIONS_FIELD
      • AGGS_FIELD

        public static final ParseField AGGS_FIELD
      • HIGHLIGHT_FIELD

        public static final ParseField HIGHLIGHT_FIELD
      • SUGGEST_FIELD

        public static final ParseField SUGGEST_FIELD
      • RESCORE_FIELD

        public static final ParseField RESCORE_FIELD
      • STATS_FIELD

        public static final ParseField STATS_FIELD
      • EXT_FIELD

        public static final ParseField EXT_FIELD
      • PROFILE_FIELD

        public static final ParseField PROFILE_FIELD
      • SEARCH_AFTER

        public static final ParseField SEARCH_AFTER
      • COLLAPSE

        public static final ParseField COLLAPSE
    • Constructor Detail

      • SearchSourceBuilder

        public SearchSourceBuilder()
        Constructs a new search source builder.
    • Method Detail

      • searchSource

        public static SearchSourceBuilder searchSource()
        A static factory method to construct a new search source.
      • highlight

        public static HighlightBuilder highlight()
        A static factory method to construct new search highlights.
      • query

        public QueryBuilder query()
        Gets the query for this request
      • postFilter

        public SearchSourceBuilder postFilter​(QueryBuilder postFilter)
        Sets a filter that will be executed after the query has been executed and only has affect on the search hits (not aggregations). This filter is always executed as last filtering mechanism.
      • postFilter

        public QueryBuilder postFilter()
        Gets the post filter for this request
      • from

        public SearchSourceBuilder from​(int from)
        From index to start the search from. Defaults to 0.
      • from

        public int from()
        Gets the from index to start the search from.
      • size

        public SearchSourceBuilder size​(int size)
        The number of search hits to return. Defaults to 10.
      • size

        public int size()
        Gets the number of search hits to return.
      • minScore

        public SearchSourceBuilder minScore​(float minScore)
        Sets the minimum score below which docs will be filtered out.
      • minScore

        public Float minScore()
        Gets the minimum score below which docs will be filtered out.
      • explain

        public Boolean explain()
        Indicates whether each search hit will be returned with an explanation of the hit (ranking)
      • version

        public Boolean version()
        Indicates whether the document's version will be included in the search hits.
      • seqNoAndPrimaryTerm

        public SearchSourceBuilder seqNoAndPrimaryTerm​(Boolean seqNoAndPrimaryTerm)
        Should each SearchHit be returned with the sequence number and primary term of the last modification of the document.
      • seqNoAndPrimaryTerm

        public Boolean seqNoAndPrimaryTerm()
        Indicates whether SearchHits should be returned with the sequence number and primary term of the last modification of the document.
      • timeout

        public TimeValue timeout()
        Gets the timeout to control how long search is allowed to take.
      • terminateAfter

        public SearchSourceBuilder terminateAfter​(int terminateAfter)
        An optional terminate_after to terminate the search after collecting terminateAfter documents
      • terminateAfter

        public int terminateAfter()
        Gets the number of documents to terminate after collecting.
      • sort

        public SearchSourceBuilder sort​(String name,
                                        SortOrder order)
        Adds a sort against the given field name and the sort ordering.
        Parameters:
        name - The name of the field
        order - The sort ordering
      • sort

        public SearchSourceBuilder sort​(String name)
        Add a sort against the given field name.
        Parameters:
        name - The name of the field to sort by
      • sorts

        public List<SortBuilder<?>> sorts()
        Gets the bytes representing the sort builders for this request.
      • trackScores

        public SearchSourceBuilder trackScores​(boolean trackScores)
        Applies when sorting, and controls if scores will be tracked as well. Defaults to false.
      • trackScores

        public boolean trackScores()
        Indicates whether scores will be tracked for this request.
      • trackTotalHits

        public SearchSourceBuilder trackTotalHits​(boolean trackTotalHits)
        Indicates if the total hit count for the query should be tracked.
      • trackTotalHitsUpTo

        @Nullable
        public Integer trackTotalHitsUpTo()
        Returns the total hit count that should be tracked or null if the value is unset. Defaults to null.
      • trackTotalHitsUpTo

        public SearchSourceBuilder trackTotalHitsUpTo​(int trackTotalHitsUpTo)
      • searchAfter

        public Object[] searchAfter()
        The sort values that indicates which docs this request should "search after". The sort values of the search_after must be equal to the number of sort fields in the query and they should be of the same type (or parsable as such). Defaults to null.
      • searchAfter

        public SearchSourceBuilder searchAfter​(Object[] values)
        Set the sort values that indicates which docs this request should "search after".
      • slice

        public SearchSourceBuilder slice​(SliceBuilder builder)
        Sets a filter that will restrict the search hits, the top hits and the aggregations to a slice of the results of the main query.
      • slice

        public SliceBuilder slice()
        Gets the slice used to filter the search hits, the top hits and the aggregations.
      • aggregations

        public AggregatorFactories.Builder aggregations()
        Gets the bytes representing the aggregation builders for this request.
      • highlighter

        public HighlightBuilder highlighter()
        Gets the highlighter builder for this request.
      • suggest

        public SuggestBuilder suggest()
        Gets the suggester builder for this request.
      • profile

        public SearchSourceBuilder profile​(boolean profile)
        Should the query be profiled. Defaults to false
      • profile

        public boolean profile()
        Return whether to profile query execution, or null if unspecified.
      • rescores

        public List<RescorerBuilder> rescores()
        Gets the bytes representing the rescore builders for this request.
      • fetchSource

        public SearchSourceBuilder fetchSource​(boolean fetch)
        Indicates whether the response should contain the stored _source for every hit
      • fetchSource

        public SearchSourceBuilder fetchSource​(@Nullable
                                               String include,
                                               @Nullable
                                               String exclude)
        Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.
        Parameters:
        include - An optional include (optionally wildcarded) pattern to filter the returned _source
        exclude - An optional exclude (optionally wildcarded) pattern to filter the returned _source
      • fetchSource

        public SearchSourceBuilder fetchSource​(@Nullable
                                               String[] includes,
                                               @Nullable
                                               String[] excludes)
        Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.
        Parameters:
        includes - An optional list of include (optionally wildcarded) pattern to filter the returned _source
        excludes - An optional list of exclude (optionally wildcarded) pattern to filter the returned _source
      • storedField

        public SearchSourceBuilder storedField​(String name)
        Adds a stored field to load and return as part of the search request. If none are specified, the source of the document will be return.
      • storedFields

        public SearchSourceBuilder storedFields​(List<String> fields)
        Sets the stored fields to load and return as part of the search request. If none are specified, the source of the document will be returned.
      • docValueField

        public SearchSourceBuilder docValueField​(String name)
        Adds a field to load from the doc values and return as part of the search request.
      • scriptField

        public SearchSourceBuilder scriptField​(String name,
                                               Script script)
        Adds a script field under the given name with the provided script.
        Parameters:
        name - The name of the field
        script - The script
      • scriptField

        public SearchSourceBuilder scriptField​(String name,
                                               Script script,
                                               boolean ignoreFailure)
        Adds a script field under the given name with the provided script.
        Parameters:
        name - The name of the field
        script - The script
      • indexBoost

        public SearchSourceBuilder indexBoost​(String index,
                                              float indexBoost)
        Sets the boost a specific index or alias will receive when the query is executed against it.
        Parameters:
        index - The index or alias to apply the boost against
        indexBoost - The boost to apply to the index
      • indexBoosts

        public List<SearchSourceBuilder.IndexBoost> indexBoosts()
        Gets the boost a specific indices or aliases will receive when the query is executed against them.
      • stats

        public List<String> stats()
        The stats groups this request will be aggregated under.
      • isSuggestOnly

        public boolean isSuggestOnly()
        Returns:
        true if the source only has suggest
      • copyWithNewSlice

        public SearchSourceBuilder copyWithNewSlice​(SliceBuilder slice)
        Create a shallow copy of this builder with a new slice configuration.
      • parseXContent

        public void parseXContent​(XContentParser parser,
                                  boolean checkTrailingTokens)
                           throws IOException
        Parse some xContent into this SearchSourceBuilder, overwriting any values specified in the xContent. Use this if you need to set up different defaults than a regular SearchSourceBuilder would have and use fromXContent(XContentParser, boolean) if you have normal defaults.
        Parameters:
        parser - The xContent parser.
        checkTrailingTokens - If true throws a parsing exception when extra tokens are found after the main object.
        Throws:
        IOException
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object