Package org.elasticsearch.search.builder
Class SearchSourceBuilder
org.elasticsearch.search.builder.SearchSourceBuilder
- All Implemented Interfaces:
Writeable
,org.elasticsearch.common.xcontent.ToXContent
,org.elasticsearch.common.xcontent.ToXContentObject
,Rewriteable<SearchSourceBuilder>
public final class SearchSourceBuilder
extends
implements Writeable, org.elasticsearch.common.xcontent.ToXContentObject, Rewriteable<SearchSourceBuilder>
A search source builder allowing to easily build search source. Simple
construction using
searchSource()
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
static org.elasticsearch.common.xcontent.ParseField
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new search source builder.Read from a stream. -
Method Summary
Modifier and TypeMethodDescriptionaddRescorer(RescorerBuilder<?> rescoreBuilder)
aggregation(AggregationBuilder aggregation)
Add an aggregation to perform as part of the search.aggregation(PipelineAggregationBuilder aggregation)
Add an aggregation to perform as part of the search.Gets the bytes representing the aggregation builders for this request.collapse()
collapse(CollapseBuilder collapse)
name)
Adds a field to load from the doc values and return as part of the search request.name, format)
Adds a field to load from the doc values and return as part of the search request.Gets the docvalue fields.boolean
obj)
explain()
Indicates whether each search hit will be returned with an explanation of the hit (ranking)explain)
Should eachSearchHit
be returned with an explanation of the hit (ranking).ext()
<SearchExtBuilder> searchExtBuilders)
name)
Adds a field to load and return as part of the search request.fetchField(FieldAndFormat fetchField)
Adds a field to load and return as part of the search request.Gets the fields to load and return as part of the search request.Gets theFetchSourceContext
which defines how the _source should be fetched.fetchSource(boolean fetch)
Indicates whether the response should contain the stored _source for every hit[] includes, [] excludes)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.include, exclude)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.fetchSource(FetchSourceContext fetchSourceContext)
Indicate how the _source should be fetched.int
from()
Gets the from index to start the search from.from(int from)
From index to start the search from.static SearchSourceBuilder
fromXContent(org.elasticsearch.common.xcontent.XContentParser parser)
static SearchSourceBuilder
fromXContent(org.elasticsearch.common.xcontent.XContentParser parser, boolean checkTrailingTokens)
int
hashCode()
static HighlightBuilder
A static factory method to construct new search highlights.Gets the highlighter builder for this request.highlighter(HighlightBuilder highlightBuilder)
Adds highlight to perform as part of the search.index, float indexBoost)
Sets the boost a specific index or alias will receive when the query is executed against it.Gets the boost a specific indices or aliases will receive when the query is executed against them.org.elasticsearch.common.xcontent.XContentBuilder
innerToXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
boolean
minScore()
Gets the minimum score below which docs will be filtered out.minScore(float minScore)
Sets the minimum score below which docs will be filtered out.void
parseXContent(org.elasticsearch.common.xcontent.XContentParser parser)
void
parseXContent(org.elasticsearch.common.xcontent.XContentParser parser, boolean checkTrailingTokens)
Parse some xContent into this SearchSourceBuilder, overwriting any values specified in the xContent.Returns the point in time that is configured with this querypointInTimeBuilder(PointInTimeBuilder builder)
Specify a point in time that this query should execute against.Gets the post filter for this requestpostFilter(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).boolean
profile()
Return whether to profile query execution, ornull
if unspecified.profile(boolean profile)
Should the query be profiled.query()
Gets the query for this requestquery(QueryBuilder query)
Sets the search query for this request.rescores()
Gets the bytes representing the rescore builders for this request.rewrite(QueryRewriteContext context)
Rewrites this search source builder into its primitive form.<,>
Mappings specified on this search request that override built in mappings.<,> runtimeMappings)
Specify the mappings specified on this search request that override built in mappings.name, Script script)
Adds a script field under the given name with the provided script.name, Script script, boolean ignoreFailure)
Adds a script field under the given name with the provided script.Gets the script fields.[]
The sort values that indicates which docs this request should "search after".[] values)
Set the sort values that indicates which docs this request should "search after".static SearchSourceBuilder
A static factory method to construct a new search source.Indicates whetherSearchHit
s should be returned with the sequence number and primary term of the last modification of the document.seqNoAndPrimaryTerm)
Should eachSearchHit
be returned with the sequence number and primary term of the last modification of the document.Create a shallow copy of this builder with a new slice configuration.int
size()
Gets the number of search hits to return.size(int size)
The number of search hits to return.slice()
Gets the slice used to filter the search hits, the top hits and the aggregations.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.name)
Add a sort against the given field name.name, SortOrder order)
Adds a sort against the given field name and the sort ordering.<SortBuilder<?>> sorts)
Sets the sort builders for this request.sort(SortBuilder<?> sort)
Adds a sort builder.<SortBuilder<?>>
sorts()
Gets the sort builders for this request.<>
stats()
The stats groups this request will be aggregated under.<> statsGroups)
The stats groups this request will be aggregated under.name)
Adds a stored field to load and return as part of the search request.Gets the stored fields context.<> fields)
Sets the stored fields to load and return as part of the search request.storedFields(StoredFieldsContext context)
Indicates how the stored fields should be fetched.suggest()
Gets the suggester builder for this request.suggest(SuggestBuilder suggestBuilder)
int
Gets the number of documents to terminate after collecting.terminateAfter(int terminateAfter)
An optional terminate_after to terminate the search after collectingterminateAfter
documentsorg.elasticsearch.core.TimeValue
timeout()
Gets the timeout to control how long search is allowed to take.timeout(org.elasticsearch.core.TimeValue timeout)
An optional timeout to control how long search is allowed to take.toString()
toString(org.elasticsearch.common.xcontent.ToXContent.Params params)
org.elasticsearch.common.xcontent.XContentBuilder
toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
boolean
Indicates whether scores will be tracked for this request.trackScores(boolean trackScores)
Applies when sorting, and controls if scores will be tracked as well.trackTotalHits(boolean trackTotalHits)
Indicates if the total hit count for the query should be tracked.Returns the total hit count that should be tracked or null if the value is unset.trackTotalHitsUpTo(int trackTotalHitsUpTo)
version()
Indicates whether the document's version will be included in the search hits.version)
Should eachSearchHit
be returned with a version associated with it.void
writeTo(StreamOutput out)
Write this into the StreamOutput.Methods inherited from class java.lang.
, , , , , , ,
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
Field Details
-
FROM_FIELD
public static final org.elasticsearch.common.xcontent.ParseField FROM_FIELD -
SIZE_FIELD
public static final org.elasticsearch.common.xcontent.ParseField SIZE_FIELD -
TIMEOUT_FIELD
public static final org.elasticsearch.common.xcontent.ParseField TIMEOUT_FIELD -
TERMINATE_AFTER_FIELD
public static final org.elasticsearch.common.xcontent.ParseField TERMINATE_AFTER_FIELD -
QUERY_FIELD
public static final org.elasticsearch.common.xcontent.ParseField QUERY_FIELD -
POST_FILTER_FIELD
public static final org.elasticsearch.common.xcontent.ParseField POST_FILTER_FIELD -
MIN_SCORE_FIELD
public static final org.elasticsearch.common.xcontent.ParseField MIN_SCORE_FIELD -
VERSION_FIELD
public static final org.elasticsearch.common.xcontent.ParseField VERSION_FIELD -
SEQ_NO_PRIMARY_TERM_FIELD
public static final org.elasticsearch.common.xcontent.ParseField SEQ_NO_PRIMARY_TERM_FIELD -
EXPLAIN_FIELD
public static final org.elasticsearch.common.xcontent.ParseField EXPLAIN_FIELD -
_SOURCE_FIELD
public static final org.elasticsearch.common.xcontent.ParseField _SOURCE_FIELD -
STORED_FIELDS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField STORED_FIELDS_FIELD -
DOCVALUE_FIELDS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField DOCVALUE_FIELDS_FIELD -
FETCH_FIELDS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField FETCH_FIELDS_FIELD -
SCRIPT_FIELDS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField SCRIPT_FIELDS_FIELD -
SCRIPT_FIELD
public static final org.elasticsearch.common.xcontent.ParseField SCRIPT_FIELD -
IGNORE_FAILURE_FIELD
public static final org.elasticsearch.common.xcontent.ParseField IGNORE_FAILURE_FIELD -
SORT_FIELD
public static final org.elasticsearch.common.xcontent.ParseField SORT_FIELD -
TRACK_SCORES_FIELD
public static final org.elasticsearch.common.xcontent.ParseField TRACK_SCORES_FIELD -
TRACK_TOTAL_HITS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField TRACK_TOTAL_HITS_FIELD -
INDICES_BOOST_FIELD
public static final org.elasticsearch.common.xcontent.ParseField INDICES_BOOST_FIELD -
AGGREGATIONS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField AGGREGATIONS_FIELD -
AGGS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField AGGS_FIELD -
HIGHLIGHT_FIELD
public static final org.elasticsearch.common.xcontent.ParseField HIGHLIGHT_FIELD -
SUGGEST_FIELD
public static final org.elasticsearch.common.xcontent.ParseField SUGGEST_FIELD -
RESCORE_FIELD
public static final org.elasticsearch.common.xcontent.ParseField RESCORE_FIELD -
STATS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField STATS_FIELD -
EXT_FIELD
public static final org.elasticsearch.common.xcontent.ParseField EXT_FIELD -
PROFILE_FIELD
public static final org.elasticsearch.common.xcontent.ParseField PROFILE_FIELD -
SEARCH_AFTER
public static final org.elasticsearch.common.xcontent.ParseField SEARCH_AFTER -
COLLAPSE
public static final org.elasticsearch.common.xcontent.ParseField COLLAPSE -
SLICE
public static final org.elasticsearch.common.xcontent.ParseField SLICE -
POINT_IN_TIME
public static final org.elasticsearch.common.xcontent.ParseField POINT_IN_TIME -
RUNTIME_MAPPINGS_FIELD
public static final org.elasticsearch.common.xcontent.ParseField RUNTIME_MAPPINGS_FIELD
-
-
Constructor Details
-
SearchSourceBuilder
public SearchSourceBuilder()Constructs a new search source builder. -
SearchSourceBuilder
Read from a stream.- Throws:
-
-
Method Details
-
fromXContent
public static SearchSourceBuilder fromXContent(org.elasticsearch.common.xcontent.XContentParser parser) throws- Throws:
-
fromXContent
public static SearchSourceBuilder fromXContent(org.elasticsearch.common.xcontent.XContentParser parser, boolean checkTrailingTokens) throws- Throws:
-
searchSource
A static factory method to construct a new search source. -
highlight
A static factory method to construct new search highlights. -
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput. -
query
Sets the search query for this request.- See Also:
QueryBuilders
-
query
Gets the query for this request -
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
Gets the post filter for this request -
from
From index to start the search from. Defaults to0
. -
from
public int from()Gets the from index to start the search from. -
size
The number of search hits to return. Defaults to10
. -
size
public int size()Gets the number of search hits to return. -
minScore
Sets the minimum score below which docs will be filtered out. -
minScore
public minScore()Gets the minimum score below which docs will be filtered out. -
explain
public explain)Should eachSearchHit
be returned with an explanation of the hit (ranking). -
explain
public explain()Indicates whether each search hit will be returned with an explanation of the hit (ranking) -
version
public version)Should eachSearchHit
be returned with a version associated with it. -
version
public version()Indicates whether the document's version will be included in the search hits. -
seqNoAndPrimaryTerm
public seqNoAndPrimaryTerm)Should eachSearchHit
be returned with the sequence number and primary term of the last modification of the document. -
seqNoAndPrimaryTerm
public seqNoAndPrimaryTerm()Indicates whetherSearchHit
s should be returned with the sequence number and primary term of the last modification of the document. -
timeout
An optional timeout to control how long search is allowed to take. -
timeout
public org.elasticsearch.core.TimeValue timeout()Gets the timeout to control how long search is allowed to take. -
terminateAfter
An optional terminate_after to terminate the search after collectingterminateAfter
documents -
terminateAfter
public int terminateAfter()Gets the number of documents to terminate after collecting. -
sort
public name, SortOrder order)Adds a sort against the given field name and the sort ordering.- Parameters:
name
- The name of the fieldorder
- The sort ordering
-
sort
public name)Add a sort against the given field name.- Parameters:
name
- The name of the field to sort by
-
sort
Adds a sort builder. -
sort
public <SortBuilder<?>> sorts)Sets the sort builders for this request. -
sorts
Gets the sort builders for this request. -
trackScores
Applies when sorting, and controls if scores will be tracked as well. Defaults tofalse
. -
trackScores
public boolean trackScores()Indicates whether scores will be tracked for this request. -
trackTotalHits
Indicates if the total hit count for the query should be tracked. -
trackTotalHitsUpTo
@Nullable public trackTotalHitsUpTo()Returns the total hit count that should be tracked or null if the value is unset. Defaults to null. -
trackTotalHitsUpTo
-
searchAfter
public [] 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 tonull
. -
searchAfter
public [] values)Set the sort values that indicates which docs this request should "search after". -
slice
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
Gets the slice used to filter the search hits, the top hits and the aggregations. -
collapse
-
collapse
-
aggregation
Add an aggregation to perform as part of the search. -
aggregation
Add an aggregation to perform as part of the search. -
aggregations
Gets the bytes representing the aggregation builders for this request. -
highlighter
Adds highlight to perform as part of the search. -
highlighter
Gets the highlighter builder for this request. -
suggest
-
suggest
Gets the suggester builder for this request. -
addRescorer
-
clearRescorers
-
profile
Should the query be profiled. Defaults tofalse
-
profile
public boolean profile()Return whether to profile query execution, ornull
if unspecified. -
rescores
Gets the bytes representing the rescore builders for this request. -
fetchSource
Indicates whether the response should contain the stored _source for every hit -
fetchSource
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 _sourceexclude
- An optional exclude (optionally wildcarded) pattern to filter the returned _source
-
fetchSource
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 _sourceexcludes
- An optional list of exclude (optionally wildcarded) pattern to filter the returned _source
-
fetchSource
Indicate how the _source should be fetched. -
fetchSource
Gets theFetchSourceContext
which defines how the _source should be fetched. -
storedField
public 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 <> 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. -
storedFields
Indicates how the stored fields should be fetched. -
storedFields
Gets the stored fields context. -
docValueFields
Gets the docvalue fields. -
docValueField
public name, @Nullable format)Adds a field to load from the doc values and return as part of the search request. -
docValueField
public name)Adds a field to load from the doc values and return as part of the search request. -
fetchFields
Gets the fields to load and return as part of the search request. -
fetchField
public name)Adds a field to load and return as part of the search request. -
fetchField
Adds a field to load and return as part of the search request.- Parameters:
fetchField
- defining the field name, optional format and optional inclusion of unmapped fields
-
scriptField
public name, Script script)Adds a script field under the given name with the provided script.- Parameters:
name
- The name of the fieldscript
- The script
-
scriptField
public name, Script script, boolean ignoreFailure)Adds a script field under the given name with the provided script.- Parameters:
name
- The name of the fieldscript
- The script
-
scriptFields
Gets the script fields. -
indexBoost
public 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 againstindexBoost
- The boost to apply to the index
-
indexBoosts
Gets the boost a specific indices or aliases will receive when the query is executed against them. -
stats
public <> statsGroups)The stats groups this request will be aggregated under. -
stats
public <> stats()The stats groups this request will be aggregated under. -
ext
public <SearchExtBuilder> searchExtBuilders) -
ext
-
isSuggestOnly
public boolean isSuggestOnly()- Returns:
- true if the source only has suggest
-
pointInTimeBuilder
Returns the point in time that is configured with this query -
pointInTimeBuilder
Specify a point in time that this query should execute against. -
runtimeMappings
public <,> runtimeMappings()Mappings specified on this search request that override built in mappings. -
runtimeMappings
public <,> runtimeMappings)Specify the mappings specified on this search request that override built in mappings. -
rewrite
Rewrites this search source builder into its primitive form. e.g. by rewriting the QueryBuilder. If the builder did not change the identity reference must be returned otherwise the builder will be rewritten infinitely.- Specified by:
rewrite
in interfaceRewriteable<SearchSourceBuilder>
- Throws:
-
shallowCopy
Create a shallow copy of this builder with a new slice configuration. -
parseXContent
public void parseXContent(org.elasticsearch.common.xcontent.XContentParser parser) throws- Throws:
-
parseXContent
public void parseXContent(org.elasticsearch.common.xcontent.XContentParser parser, boolean checkTrailingTokens) throwsParse 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 usefromXContent(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:
-
innerToXContent
public org.elasticsearch.common.xcontent.XContentBuilder innerToXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws- Throws:
-
toXContent
public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws- Specified by:
toXContent
in interfaceorg.elasticsearch.common.xcontent.ToXContent
- Throws:
-
hashCode
public int hashCode()- Overrides:
in class
-
equals
public boolean equals( obj)- Overrides:
in class
-
toString
public toString()- Overrides:
in class
-
toString
public toString(org.elasticsearch.common.xcontent.ToXContent.Params params)
-