Package org.opensearch.action.search
Class SearchRequest
java.lang.Object
org.opensearch.core.transport.TransportMessage
org.opensearch.transport.TransportRequest
org.opensearch.action.ActionRequest
org.opensearch.action.search.SearchRequest
- All Implemented Interfaces:
IndicesRequest
,IndicesRequest.Replaceable
,org.opensearch.core.common.io.stream.Writeable
,TaskAwareRequest
- Direct Known Subclasses:
PipelinedRequest
@PublicApi(since="1.0.0")
public class SearchRequest
extends ActionRequest
implements IndicesRequest.Replaceable
A request to execute search against one or more indices (or all). Best created using
Requests.searchRequest(String...)
.
Note, the search source(org.opensearch.search.builder.SearchSourceBuilder)
is required. The search source is the different search options, including aggregations and such.
- See Also:
- Opensearch.api:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.opensearch.transport.TransportRequest
TransportRequest.Empty
Nested classes/interfaces inherited from interface org.opensearch.action.IndicesRequest
IndicesRequest.Replaceable
Nested classes/interfaces inherited from interface org.opensearch.core.common.io.stream.Writeable
org.opensearch.core.common.io.stream.Writeable.Reader<V>, org.opensearch.core.common.io.stream.Writeable.WriteableRegistry, org.opensearch.core.common.io.stream.Writeable.Writer<V>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final IndicesOptions
static final int
static final org.opensearch.core.xcontent.ToXContent.Params
-
Constructor Summary
ConstructorsConstructorDescriptionSearchRequest
(String... indices) Constructs a new search request against the indices.SearchRequest
(String[] indices, SearchSourceBuilder source) Constructs a new search request against the provided indices with the given search source.SearchRequest
(SearchRequest searchRequest) Constructs a new search request from the provided search requestSearchRequest
(org.opensearch.core.common.io.stream.StreamInput in) Constructs a new search request from reading the specified stream. -
Method Summary
Modifier and TypeMethodDescriptionallowPartialSearchResults
(boolean allowPartialSearchResults) Sets if this request should allow partial results.final String
createTask
(long id, String type, String action, org.opensearch.core.tasks.TaskId parentTaskId, Map<String, String> headers) Returns the task object that should be used to keep track of the processing of the request.boolean
int
Returns the number of shard results that should be reduced at once on the coordinating node.org.opensearch.common.unit.TimeValue
int
Returns the number of shard requests that should be executed concurrently on a single node.long
Returns the current time in milliseconds from the time epoch, to be used for the execution of this search request.Returns 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, ornull
if the threshold is unspecified.int
hashCode()
boolean
Determines whether the request should be applied to data streams.String[]
indices()
The indicesSets the indices the search will be executed on.Returns the indices options used to resolve indices.indicesOptions
(IndicesOptions indicesOptions) boolean
Returns whether network round-trips should be minimized when executing cross-cluster search requests.Returns value of user-provided phase_took query parameter for this search request.boolean
pipeline()
preference
(String preference) Sets the preference to execute the search.requestCache
(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).int
static int
resolveTrackTotalHitsUpTo
(Scroll scroll, SearchSourceBuilder source) routing()
A comma separated list of routing values to control the shards the search will be executed on.A comma separated list of routing values to control the shards the search will be executed on.The routing values to control the shards that the search will be executed on.scroll()
If set, will enable scrolling of the search request.If set, will enable scrolling of the search request for the specified timeout.scroll
(org.opensearch.common.unit.TimeValue keepAlive) If set, will enable scrolling of the search request for the specified timeout.If set, will enable scrolling of the search request.The type of search to execute.searchType
(String searchType) The a string representation search type to execute, defaults toSearchType.DEFAULT
.searchType
(SearchType searchType) The search type to execute, defaults toSearchType.DEFAULT
.void
setBatchedReduceSize
(int batchedReduceSize) Sets the number of shard results that should be reduced at once on the coordinating node.void
setCancelAfterTimeInterval
(org.opensearch.common.unit.TimeValue cancelAfterTimeInterval) void
setCcsMinimizeRoundtrips
(boolean ccsMinimizeRoundtrips) Sets whether network round-trips should be minimized when executing cross-cluster search requests.void
setMaxConcurrentShardRequests
(int maxConcurrentShardRequests) Sets the number of shard requests that should be executed concurrently on a single node.void
setPhaseTook
(Boolean phaseTook) Sets value of phase_took query param if provided by user.void
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.source()
The search source to execute.source
(SearchSourceBuilder sourceBuilder) The source of the search request.toString()
validate()
void
writeTo
(org.opensearch.core.common.io.stream.StreamOutput out) Methods inherited from class org.opensearch.action.ActionRequest
getShouldStoreResult
Methods inherited from class org.opensearch.transport.TransportRequest
getParentTask, setParentTask
Methods inherited from class org.opensearch.core.transport.TransportMessage
remoteAddress, remoteAddress
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opensearch.tasks.TaskAwareRequest
getDescription, setParentTask
-
Field Details
-
FORMAT_PARAMS
public static final org.opensearch.core.xcontent.ToXContent.Params FORMAT_PARAMS -
DEFAULT_PRE_FILTER_SHARD_SIZE
public static final int DEFAULT_PRE_FILTER_SHARD_SIZE- See Also:
-
DEFAULT_BATCHED_REDUCE_SIZE
public static final int DEFAULT_BATCHED_REDUCE_SIZE- See Also:
-
DEFAULT_INDICES_OPTIONS
-
-
Constructor Details
-
SearchRequest
public SearchRequest() -
SearchRequest
Constructs a new search request from the provided search request -
SearchRequest
Constructs a new search request against the indices. No indices provided here means that search will run against all indices. -
SearchRequest
Constructs a new search request against the provided indices with the given search source. -
SearchRequest
Constructs a new search request from reading the specified stream.- Parameters:
in
- The stream the request is read from- Throws:
IOException
- if there is an issue reading the stream
-
-
Method Details
-
writeTo
- Specified by:
writeTo
in interfaceorg.opensearch.core.common.io.stream.Writeable
- Overrides:
writeTo
in classActionRequest
- Throws:
IOException
-
validate
- Specified by:
validate
in classActionRequest
-
getOrCreateAbsoluteStartMillis
public long getOrCreateAbsoluteStartMillis()Returns the current time in milliseconds from the time epoch, to be used for the execution of this search request. Used to ensure that the same value, determined by the coordinating node, is used on all nodes involved in the execution of the search request. When created throughsubSearchRequest(SearchRequest, String[], String, long, boolean)
, this method returns the provided current time, otherwise it will returnSystem.currentTimeMillis()
. -
indices
Sets the indices the search will be executed on.- Specified by:
indices
in interfaceIndicesRequest.Replaceable
-
indicesOptions
Description copied from interface:IndicesRequest
Returns the indices options used to resolve indices. They tell for instance whether a single index is accepted, whether an empty array will be converted to _all, and how wildcards will be expanded if needed.- Specified by:
indicesOptions
in interfaceIndicesRequest
-
indicesOptions
-
includeDataStreams
public boolean includeDataStreams()Description copied from interface:IndicesRequest
Determines whether the request should be applied to data streams. Whenfalse
, none of the names or wildcard expressions inIndicesRequest.indices()
should be applied to or expanded to any data streams. All layers involved in the request's fulfillment including security, name resolution, etc., should respect this flag.- Specified by:
includeDataStreams
in interfaceIndicesRequest
-
isCcsMinimizeRoundtrips
public boolean isCcsMinimizeRoundtrips()Returns whether network round-trips should be minimized when executing cross-cluster search requests. Defaults totrue
. -
setCcsMinimizeRoundtrips
public void setCcsMinimizeRoundtrips(boolean ccsMinimizeRoundtrips) Sets whether network round-trips should be minimized when executing cross-cluster search requests. Defaults totrue
. -
routing
A comma separated list of routing values to control the shards the search will be executed on. -
routing
A comma separated list of routing values to control the shards the search will be executed on. -
routing
The routing values to control the shards that the search will be executed on. -
preference
Sets the preference to execute the search. Defaults to randomize across shards. Can be set to_local
to prefer local shards,_primary
to execute only on primary shards, or a custom value, which guarantees that the same order will be used across different requests. -
preference
-
searchType
The search type to execute, defaults toSearchType.DEFAULT
. -
searchType
The a string representation search type to execute, defaults toSearchType.DEFAULT
. Can be one of "dfs_query_then_fetch"/"dfsQueryThenFetch", "dfs_query_and_fetch"/"dfsQueryAndFetch", "query_then_fetch"/"queryThenFetch", and "query_and_fetch"/"queryAndFetch". -
source
The source of the search request. -
source
The search source to execute. -
pointInTimeBuilder
-
searchType
The type of search to execute. -
indices
The indices- Specified by:
indices
in interfaceIndicesRequest
-
scroll
If set, will enable scrolling of the search request. -
scroll
If set, will enable scrolling of the search request. -
scroll
If set, will enable scrolling of the search request for the specified timeout. -
scroll
If set, will enable scrolling of the search request for the specified timeout. -
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). By default (not set, or null, will default to the index level setting if request cache is enabled or not). -
requestCache
-
allowPartialSearchResults
Sets if this request should allow partial results. (If method is not called, will default to the cluster level setting). -
allowPartialSearchResults
-
setBatchedReduceSize
public void setBatchedReduceSize(int batchedReduceSize) 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. -
getBatchedReduceSize
public int getBatchedReduceSize()Returns 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. -
getMaxConcurrentShardRequests
public int getMaxConcurrentShardRequests()Returns 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
-
setMaxConcurrentShardRequests
public void setMaxConcurrentShardRequests(int maxConcurrentShardRequests) 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
public void 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. 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
-
isPhaseTook
Returns value of user-provided phase_took query parameter for this search request. -
setPhaseTook
Sets value of phase_took query param if provided by user. Defaults tonull
. -
getPreFilterShardSize
Returns 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, ornull
if the threshold is unspecified. 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
-
isSuggestOnly
public boolean isSuggestOnly()- Returns:
- true if the request only has suggest
-
resolveTrackTotalHitsUpTo
public int resolveTrackTotalHitsUpTo() -
resolveTrackTotalHitsUpTo
-
setCancelAfterTimeInterval
public void setCancelAfterTimeInterval(org.opensearch.common.unit.TimeValue cancelAfterTimeInterval) -
getCancelAfterTimeInterval
public org.opensearch.common.unit.TimeValue getCancelAfterTimeInterval() -
pipeline
-
pipeline
-
createTask
public SearchTask createTask(long id, String type, String action, org.opensearch.core.tasks.TaskId parentTaskId, Map<String, String> headers) Description copied from interface:TaskAwareRequest
Returns the task object that should be used to keep track of the processing of the request.- Specified by:
createTask
in interfaceTaskAwareRequest
-
buildDescription
-
equals
-
hashCode
public int hashCode() -
toString
-