Package org.elasticsearch.action.search
Class SearchRequest
- java.lang.Object
-
- org.elasticsearch.transport.TransportMessage
-
- org.elasticsearch.transport.TransportRequest
-
- org.elasticsearch.action.ActionRequest
-
- org.elasticsearch.action.search.SearchRequest
-
- All Implemented Interfaces:
IndicesRequest
,IndicesRequest.Replaceable
,Streamable
,Writeable
,TaskAwareRequest
public final class SearchRequest extends ActionRequest implements IndicesRequest.Replaceable
A request to execute search against one or more indices (or all). Best created usingRequests.searchRequest(String...)
.Note, the search
source(org.elasticsearch.search.builder.SearchSourceBuilder)
is required. The search source is the different search options, including aggregations and such.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportRequest
TransportRequest.Empty
-
Nested classes/interfaces inherited from interface org.elasticsearch.action.IndicesRequest
IndicesRequest.Replaceable
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BATCHED_REDUCE_SIZE
static IndicesOptions
DEFAULT_INDICES_OPTIONS
static int
DEFAULT_PRE_FILTER_SHARD_SIZE
-
Constructor Summary
Constructors Constructor Description SearchRequest()
SearchRequest(java.lang.String... indices)
Constructs a new search request against the indices.SearchRequest(java.lang.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 request
-
Method Summary
Modifier and Type Method Description java.lang.Boolean
allowPartialSearchResults()
SearchRequest
allowPartialSearchResults(boolean allowPartialSearchResults)
Sets if this request should allow partial results.Task
createTask(long id, java.lang.String type, java.lang.String action, TaskId parentTaskId, java.util.Map<java.lang.String,java.lang.String> headers)
Returns the task object that should be used to keep track of the processing of the request.boolean
equals(java.lang.Object o)
int
getBatchedReduceSize()
Returns the number of shard results that should be reduced at once on the coordinating node.int
getMaxConcurrentShardRequests()
Returns the number of shard requests that should be executed concurrently.int
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.int
hashCode()
java.lang.String[]
indices()
The indicesSearchRequest
indices(java.lang.String... indices)
Sets the indices the search will be executed on.IndicesOptions
indicesOptions()
Returns the indices options used to resolve indices.SearchRequest
indicesOptions(IndicesOptions indicesOptions)
boolean
isSuggestOnly()
java.lang.String
preference()
SearchRequest
preference(java.lang.String preference)
Sets the preference to execute the search.void
readFrom(StreamInput in)
Set this object's fields from a StreamInput.java.lang.Boolean
requestCache()
SearchRequest
requestCache(java.lang.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).java.lang.String
routing()
A comma separated list of routing values to control the shards the search will be executed on.SearchRequest
routing(java.lang.String routing)
A comma separated list of routing values to control the shards the search will be executed on.SearchRequest
routing(java.lang.String... routings)
The routing values to control the shards that the search will be executed on.Scroll
scroll()
If set, will enable scrolling of the search request.SearchRequest
scroll(java.lang.String keepAlive)
If set, will enable scrolling of the search request for the specified timeout.SearchRequest
scroll(TimeValue keepAlive)
If set, will enable scrolling of the search request for the specified timeout.SearchRequest
scroll(Scroll scroll)
If set, will enable scrolling of the search request.SearchType
searchType()
The tye of search to execute.SearchRequest
searchType(java.lang.String searchType)
The a string representation search type to execute, defaults toSearchType.DEFAULT
.SearchRequest
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
setMaxConcurrentShardRequests(int maxConcurrentShardRequests)
Sets the number of shard requests that should be executed concurrently.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.SearchSourceBuilder
source()
The search source to execute.SearchRequest
source(SearchSourceBuilder sourceBuilder)
The source of the search request.java.lang.String
toString()
java.lang.String[]
types()
The document types to execute the search against.SearchRequest
types(java.lang.String... types)
The document types to execute the search against.ActionRequestValidationException
validate()
void
writeTo(StreamOutput out)
Write this object's fields to a StreamOutput.-
Methods inherited from class org.elasticsearch.action.ActionRequest
getShouldStoreResult
-
Methods inherited from class org.elasticsearch.transport.TransportRequest
getParentTask, setParentTask
-
Methods inherited from class org.elasticsearch.transport.TransportMessage
remoteAddress, remoteAddress
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.tasks.TaskAwareRequest
getDescription, setParentTask
-
-
-
-
Field Detail
-
DEFAULT_PRE_FILTER_SHARD_SIZE
public static final int DEFAULT_PRE_FILTER_SHARD_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_BATCHED_REDUCE_SIZE
public static final int DEFAULT_BATCHED_REDUCE_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_INDICES_OPTIONS
public static final IndicesOptions DEFAULT_INDICES_OPTIONS
-
-
Constructor Detail
-
SearchRequest
public SearchRequest()
-
SearchRequest
public SearchRequest(SearchRequest searchRequest)
Constructs a new search request from the provided search request
-
SearchRequest
public SearchRequest(java.lang.String... indices)
Constructs a new search request against the indices. No indices provided here means that search will run against all indices.
-
SearchRequest
public SearchRequest(java.lang.String[] indices, SearchSourceBuilder source)
Constructs a new search request against the provided indices with the given search source.
-
-
Method Detail
-
validate
public ActionRequestValidationException validate()
- Specified by:
validate
in classActionRequest
-
indices
public SearchRequest indices(java.lang.String... indices)
Sets the indices the search will be executed on.- Specified by:
indices
in interfaceIndicesRequest.Replaceable
-
indicesOptions
public IndicesOptions 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
public SearchRequest indicesOptions(IndicesOptions indicesOptions)
-
types
public java.lang.String[] types()
The document types to execute the search against. Defaults to be executed against all types.
-
types
public SearchRequest types(java.lang.String... types)
The document types to execute the search against. Defaults to be executed against all types.
-
routing
public java.lang.String routing()
A comma separated list of routing values to control the shards the search will be executed on.
-
routing
public SearchRequest routing(java.lang.String routing)
A comma separated list of routing values to control the shards the search will be executed on.
-
routing
public SearchRequest routing(java.lang.String... routings)
The routing values to control the shards that the search will be executed on.
-
preference
public SearchRequest preference(java.lang.String 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
public java.lang.String preference()
-
searchType
public SearchRequest searchType(SearchType searchType)
The search type to execute, defaults toSearchType.DEFAULT
.
-
searchType
public SearchRequest searchType(java.lang.String 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
public SearchRequest source(SearchSourceBuilder sourceBuilder)
The source of the search request.
-
source
public SearchSourceBuilder source()
The search source to execute.
-
searchType
public SearchType searchType()
The tye of search to execute.
-
indices
public java.lang.String[] indices()
The indices- Specified by:
indices
in interfaceIndicesRequest
-
scroll
public Scroll scroll()
If set, will enable scrolling of the search request.
-
scroll
public SearchRequest scroll(Scroll scroll)
If set, will enable scrolling of the search request.
-
scroll
public SearchRequest scroll(TimeValue keepAlive)
If set, will enable scrolling of the search request for the specified timeout.
-
scroll
public SearchRequest scroll(java.lang.String keepAlive)
If set, will enable scrolling of the search request for the specified timeout.
-
requestCache
public SearchRequest requestCache(java.lang.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). By default (not set, or null, will default to the index level setting if request cache is enabled or not).
-
requestCache
public java.lang.Boolean requestCache()
-
allowPartialSearchResults
public SearchRequest allowPartialSearchResults(boolean allowPartialSearchResults)
Sets if this request should allow partial results. (If method is not called, will default to the cluster level setting).
-
allowPartialSearchResults
public java.lang.Boolean 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. This value should be used as a protection mechanism to reduce the number of shard reqeusts 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 grows with the number of nodes in the cluster but is at most256
.
-
setMaxConcurrentShardRequests
public void setMaxConcurrentShardRequests(int maxConcurrentShardRequests)
Sets the number of shard requests that should be executed concurrently. 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 grows with the number of nodes in the cluster but is at most256
.
-
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 it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. The default is128
-
getPreFilterShardSize
public int 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. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint. The default is128
-
isSuggestOnly
public boolean isSuggestOnly()
- Returns:
- true if the request only has suggest
-
createTask
public Task createTask(long id, java.lang.String type, java.lang.String action, TaskId parentTaskId, java.util.Map<java.lang.String,java.lang.String> headers)
Description copied from interface:TaskAwareRequest
Returns the task object that should be used to keep track of the processing of the request. A request can override this method and return null to avoid being tracked by the task manager.- Specified by:
createTask
in interfaceTaskAwareRequest
-
readFrom
public void readFrom(StreamInput in) throws java.io.IOException
Description copied from interface:Streamable
Set this object's fields from a StreamInput.- Specified by:
readFrom
in interfaceStreamable
- Overrides:
readFrom
in classActionRequest
- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Streamable
Write this object's fields to a StreamOutput.- Specified by:
writeTo
in interfaceStreamable
- Specified by:
writeTo
in interfaceWriteable
- Overrides:
writeTo
in classActionRequest
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-