Package org.elasticsearch.action.search
Class SearchRequestBuilder
java.lang.Object
org.elasticsearch.action.ActionRequestBuilder<SearchRequest,SearchResponse>
org.elasticsearch.action.search.SearchRequestBuilder
A search action request builder.
-
Field Summary
Fields inherited from class org.elasticsearch.action.ActionRequestBuilder
action, client, request
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAggregation(AggregationBuilder aggregation)
Adds an aggregation to the search operation.addAggregation(PipelineAggregationBuilder aggregation)
Adds an aggregation to the search operation.addDocValueField(String name)
Adds a docvalue based field to load and return.addDocValueField(String name, String format)
Adds a docvalue based field to load and return.addFetchField(String name)
Adds a field to load and return.addFetchField(FieldAndFormat fetchField)
Adds a field to load and return.addIndexBoost(String index, float indexBoost)
Sets the boost a specific index will receive when the query is executed against it.addRescorer(RescorerBuilder<?> rescorer)
Adds a new rescorer.addRescorer(RescorerBuilder<?> rescorer, int window)
Adds a new rescorer.addScriptField(String name, Script script)
Adds a script based field to load and return.Adds a sort against the given field name and the sort ordering.addSort(SortBuilder<?> sort)
Adds a generic sort builder.addStoredField(String field)
Adds a stored field to load and return (note, it must be stored) as part of the search request.Clears all rescorers from the builder.highlighter(HighlightBuilder highlightBuilder)
searchAfter(Object[] values)
Set the sort values that indicates which docs this request should "search after".seqNoAndPrimaryTerm(boolean seqNoAndPrimaryTerm)
Should eachSearchHit
be returned with the sequence number and primary term of the last modification of the document.setAllowPartialSearchResults(boolean allowPartialSearchResults)
Sets if this request should allow partial results.setBatchedReduceSize(int batchedReduceSize)
Sets the number of shard results that should be reduced at once on the coordinating node.setCollapse(CollapseBuilder collapse)
setExplain(boolean explain)
Should eachSearchHit
be returned with an explanation of the hit (ranking).setFetchSource(boolean fetch)
Indicates whether the response should contain the stored _source for every hitsetFetchSource(String[] includes, String[] excludes)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.setFetchSource(String include, String exclude)
Indicate that _source should be returned with every hit, with an "include" and/or "exclude" set which can include simple wildcard elements.setFrom(int from)
From index to start the search from.setIndices(String... indices)
Sets the indices the search will be executed on.setIndicesOptions(IndicesOptions indicesOptions)
Specifies what type of requested indices to ignore and wildcard indices expressions.setMaxConcurrentShardRequests(int maxConcurrentShardRequests)
Sets the number of shard requests that should be executed concurrently on a single node.setMinScore(float minScore)
Sets the minimum score below which docs will be filtered out.setPointInTime(PointInTimeBuilder pointInTimeBuilder)
If specified, Elasticsearch will execute this search request using reader contexts from that point in time.setPostFilter(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).setPreference(String preference)
Sets the preference to execute the search.setPreFilterShardSize(int preFilterShardSize)
Sets a threshold that enforces a pre-filter roundtrip to pre-filter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold.setProfile(boolean profile)
Should the query be profiled.setQuery(QueryBuilder queryBuilder)
Constructs a new search source builder with a search query.setRequestCache(Boolean requestCache)
Sets if this request should use the request cache or not, assuming that it can (for example, if "now" is used, it will never be cached).setRescorer(RescorerBuilder<?> rescorer)
Clears all rescorers on the builder and sets the first one.setRescorer(RescorerBuilder rescorer, int window)
Clears all rescorers on the builder and sets the first one.setRouting(String routing)
A comma separated list of routing values to control the shards the search will be executed on.setRouting(String... routing)
The routing values to control the shards that the search will be executed on.setRuntimeMappings(Map<String,Object> runtimeMappings)
Set runtime mappings to create runtime fields that exist only as part of this particular search.If set, will enable scrolling of the search request for the specified timeout.setScroll(org.elasticsearch.core.TimeValue keepAlive)
If set, will enable scrolling of the search request for the specified timeout.If set, will enable scrolling of the search request.setSearchType(String searchType)
The a string representation search type to execute, defaults toSearchType.DEFAULT
.setSearchType(SearchType searchType)
The search type to execute, defaults toSearchType.DEFAULT
.setSize(int size)
The number of search hits to return.setSource(SearchSourceBuilder source)
Sets the source of the request as a SearchSourceBuilder.The stats groups this request will be aggregated under.The stats groups this request will be aggregated under.setTerminateAfter(int terminateAfter)
An optional document count, upon collecting which the search query will early terminatesetTimeout(org.elasticsearch.core.TimeValue timeout)
An optional timeout to control how long search is allowed to take.setTrackScores(boolean trackScores)
Applies when sorting, and controls if scores will be tracked as well.setTrackTotalHits(boolean trackTotalHits)
Indicates if the total hit count for the query should be tracked.setTrackTotalHitsUpTo(int trackTotalHitsUpTo)
Indicates the total hit count that should be tracked accurately or null if the value is unset.Deprecated.Types are going away, prefer filtering on a field.setVersion(boolean version)
Should eachSearchHit
be returned with its version.slice(SliceBuilder builder)
storedFields(String... fields)
Adds stored fields to load and return (note, it must be stored) as part of the search request.suggest(SuggestBuilder suggestBuilder)
Delegates toSearchSourceBuilder.suggest(SuggestBuilder)
toString()
-
Constructor Details
-
SearchRequestBuilder
-
-
Method Details
-
setIndices
Sets the indices the search will be executed on. -
setTypes
Deprecated.Types are going away, prefer filtering on a field.The document types to execute the search against. Defaults to be executed against all types. -
setSearchType
The search type to execute, defaults toSearchType.DEFAULT
. -
setSearchType
The a string representation search type to execute, defaults toSearchType.DEFAULT
. Can be one of "dfs_query_then_fetch" or "query_then_fetch". -
setScroll
If set, will enable scrolling of the search request. -
setScroll
If set, will enable scrolling of the search request for the specified timeout. -
setScroll
If set, will enable scrolling of the search request for the specified timeout. -
setTimeout
An optional timeout to control how long search is allowed to take. -
setTerminateAfter
An optional document count, upon collecting which the search query will early terminate -
setRouting
A comma separated list of routing values to control the shards the search will be executed on. -
setRouting
The routing values to control the shards that the search will be executed on. -
setPreference
Sets the preference to execute the search. Defaults to randomize across shards. Can be set to_local
to prefer local shards or a custom value, which guarantees that the same order will be used across different requests. -
setIndicesOptions
Specifies what type of requested indices to ignore and wildcard indices expressions.For example indices that don't exist.
-
setQuery
Constructs a new search source builder with a search query.- See Also:
QueryBuilders
-
setPostFilter
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. -
setMinScore
Sets the minimum score below which docs will be filtered out. -
setFrom
From index to start the search from. Defaults to0
. -
setSize
The number of search hits to return. Defaults to10
. -
setExplain
Should eachSearchHit
be returned with an explanation of the hit (ranking). -
setVersion
Should eachSearchHit
be returned with its version. -
seqNoAndPrimaryTerm
Should eachSearchHit
be returned with the sequence number and primary term of the last modification of the document. -
addIndexBoost
Sets the boost a specific index will receive when the query is executed against it.- Parameters:
index
- The index to apply the boost againstindexBoost
- The boost to apply to the index
-
setStats
The stats groups this request will be aggregated under. -
setStats
The stats groups this request will be aggregated under. -
setFetchSource
Indicates whether the response should contain the stored _source for every hit -
setFetchSource
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
-
setFetchSource
public SearchRequestBuilder setFetchSource(@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 _sourceexcludes
- An optional list of exclude (optionally wildcarded) pattern to filter the returned _source
-
addDocValueField
Adds a docvalue based field to load and return. The field does not have to be stored, but its recommended to use non analyzed or numeric fields.- Parameters:
name
- The field to get from the docvalue
-
addDocValueField
Adds a docvalue based field to load and return. The field does not have to be stored, but its recommended to use non analyzed or numeric fields.- Parameters:
name
- The field to get from the docvalue
-
addFetchField
Adds a field to load and return. The field must be present in the document _source.- Parameters:
name
- The field to load
-
addFetchField
Adds a field to load and return. The field must be present in the document _source.- Parameters:
fetchField
- aFieldAndFormat
specifying the field pattern, optional format (for example a date format) and whether this field pattern sould also include unmapped fields
-
addStoredField
Adds a stored field to load and return (note, it must be stored) as part of the search request. -
addScriptField
Adds a script based field to load and return. The field does not have to be stored, but its recommended to use non analyzed or numeric fields.- Parameters:
name
- The name that will represent this value in the return hitscript
- The script to use
-
addSort
Adds a sort against the given field name and the sort ordering.- Parameters:
field
- The name of the fieldorder
- The sort ordering
-
addSort
Adds a generic sort builder.- See Also:
SortBuilders
-
searchAfter
Set the sort values that indicates which docs this request should "search after". -
slice
-
setTrackScores
Applies when sorting, and controls if scores will be tracked as well. Defaults tofalse
. -
setTrackTotalHits
Indicates if the total hit count for the query should be tracked. Requests will count total hit count accurately up to 10,000 by default, seesetTrackTotalHitsUpTo(int)
to change this value or set to true/false to always/never count accurately. -
setTrackTotalHitsUpTo
Indicates the total hit count that should be tracked accurately or null if the value is unset. Defaults to 10,000. -
storedFields
Adds stored fields to load and return (note, it must be stored) as part of the search request. To disable the stored fields entirely (source and metadata fields) usestoredField("_none_")
. -
addAggregation
Adds an aggregation to the search operation. -
addAggregation
Adds an aggregation to the search operation. -
highlighter
-
suggest
Delegates toSearchSourceBuilder.suggest(SuggestBuilder)
-
setRescorer
Clears all rescorers on the builder and sets the first one. To use multiple rescore windows useaddRescorer(org.elasticsearch.search.rescore.RescorerBuilder, int)
.- Parameters:
rescorer
- rescorer configuration- Returns:
- this for chaining
-
setRescorer
Clears all rescorers on the builder and sets the first one. To use multiple rescore windows useaddRescorer(org.elasticsearch.search.rescore.RescorerBuilder, int)
.- Parameters:
rescorer
- rescorer configurationwindow
- rescore window- Returns:
- this for chaining
-
addRescorer
Adds a new rescorer.- Parameters:
rescorer
- rescorer configuration- Returns:
- this for chaining
-
addRescorer
Adds a new rescorer.- Parameters:
rescorer
- rescorer configurationwindow
- rescore window- Returns:
- this for chaining
-
clearRescorers
Clears all rescorers from the builder.- Returns:
- this for chaining
-
setSource
Sets the source of the request as a SearchSourceBuilder. -
setRequestCache
Sets if this request should use the request cache or not, assuming that it can (for example, if "now" is used, it will never be cached). By default (not set, or null, will default to the index level setting if request cache is enabled or not). -
setAllowPartialSearchResults
Sets if this request should allow partial results. (If method is not called, will default to the cluster level setting). -
setProfile
Should the query be profiled. Defaults tofalse
-
setCollapse
-
setPointInTime
If specified, Elasticsearch will execute this search request using reader contexts from that point in time. -
toString
-
setBatchedReduceSize
Sets the number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large. -
setMaxConcurrentShardRequests
Sets the number of shard requests that should be executed concurrently on a single node. This value should be used as a protection mechanism to reduce the number of shard requests fired per high level search request. Searches that hit the entire cluster can be throttled with this number to reduce the cluster load. The default is5
. -
setPreFilterShardSize
Sets a threshold that enforces a pre-filter roundtrip to pre-filter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. When unspecified, the pre-filter phase is executed if any of these conditions is met:- The request targets more than 128 shards
- The request targets one or more read-only index
- The primary sort of the query targets an indexed field
-
setRuntimeMappings
Set runtime mappings to create runtime fields that exist only as part of this particular search.
-