org.elasticsearch.action.search
Class SearchRequest

java.lang.Object
  extended by org.elasticsearch.action.search.SearchRequest
All Implemented Interfaces:
ActionRequest, Streamable

public class SearchRequest
extends java.lang.Object
implements ActionRequest

A request to execute search against one or more indices (or all). Best created using Requests.searchRequest(String...).

Note, the search source(org.elasticsearch.search.builder.SearchSourceBuilder) is required. The search source is the different search options, including facets and such.

There is an option to specify an addition search source using the extraSource(org.elasticsearch.search.builder.SearchSourceBuilder).

See Also:
Requests.searchRequest(String...), Client.search(SearchRequest), SearchResponse

Constructor Summary
SearchRequest()
           
SearchRequest(java.lang.String... indices)
          Constructs a new search request against the indices.
SearchRequest(java.lang.String[] indices, byte[] source)
          Constructs a new search request against the provided indices with the given search source.
 
Method Summary
 void beforeLocalFork()
          Internal.
 byte[] extraSource()
          Additional search source to execute.
 SearchRequest extraSource(byte[] source)
          Allows to provide additional source that will be used as well.
 SearchRequest extraSource(byte[] source, int offset, int length)
          Allows to provide additional source that will be used as well.
 SearchRequest extraSource(byte[] source, int offset, int length, boolean unsafe)
          Allows to provide additional source that will be used as well.
 SearchRequest extraSource(java.util.Map extraSource)
           
 SearchRequest extraSource(SearchSourceBuilder sourceBuilder)
          Allows to provide additional source that will be used as well.
 SearchRequest extraSource(java.lang.String source)
          Allows to provide additional source that will use used as well.
 SearchRequest extraSource(XContentBuilder builder)
           
 int extraSourceLength()
           
 int extraSourceOffset()
           
 java.lang.String[] indices()
          The indices
 SearchRequest indices(java.lang.String... indices)
          Sets the indices the search will be executed on.
 boolean listenerThreaded()
          Should the listener be called on a separate thread if needed.
 SearchRequest listenerThreaded(boolean listenerThreaded)
          Should the listener be called on a separate thread if needed.
 SearchOperationThreading operationThreading()
          Controls the the search operation threading model.
 SearchRequest operationThreading(SearchOperationThreading operationThreading)
          Controls the the search operation threading model.
 SearchRequest operationThreading(java.lang.String operationThreading)
          Sets the string representation of the operation threading model.
 java.lang.String preference()
           
 SearchRequest preference(java.lang.String preference)
          Sets the preference to execute the search.
 java.lang.String queryHint()
          A query hint to optionally later be used when routing the request.
 SearchRequest queryHint(java.lang.String queryHint)
          A query hint to optionally later be used when routing the request.
 void readFrom(StreamInput in)
           
 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.
 SearchRequest routing(java.lang.String routing)
          A comma separated list of routing values to control the shards the search will be executed on.
 Scroll scroll()
          If set, will enable scrolling of the search request.
 SearchRequest scroll(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.
 SearchType searchType()
          The tye of search to execute.
 SearchRequest searchType(SearchType searchType)
          The search type to execute, defaults to SearchType.DEFAULT.
 SearchRequest searchType(java.lang.String searchType)
          The a string representation search type to execute, defaults to SearchType.DEFAULT.
 byte[] source()
          The search source to execute.
 SearchRequest source(byte[] source)
          The search source to execute.
 SearchRequest source(byte[] source, int offset, int length)
          The search source to execute.
 SearchRequest source(byte[] source, int offset, int length, boolean unsafe)
          The search source to execute.
 SearchRequest source(java.util.Map source)
          The source of the search request in the form of a map.
 SearchRequest source(SearchSourceBuilder sourceBuilder)
          The source of the search request.
 SearchRequest source(java.lang.String source)
          The source of the search request.
 SearchRequest source(XContentBuilder builder)
           
 int sourceLength()
           
 int sourceOffset()
           
 TimeValue timeout()
          An optional timeout to control how long search is allowed to take.
 SearchRequest timeout(java.lang.String timeout)
          An optional timeout to control how long search is allowed to take.
 SearchRequest timeout(TimeValue timeout)
          An optional timeout to control how long search is allowed to take.
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SearchRequest

public SearchRequest()

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,
                     byte[] 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 interface ActionRequest

beforeLocalFork

public void beforeLocalFork()
Internal.


listenerThreaded

public boolean listenerThreaded()
Should the listener be called on a separate thread if needed.

Specified by:
listenerThreaded in interface ActionRequest

indices

public SearchRequest indices(java.lang.String... indices)
Sets the indices the search will be executed on.


listenerThreaded

public SearchRequest listenerThreaded(boolean listenerThreaded)
Should the listener be called on a separate thread if needed.

Specified by:
listenerThreaded in interface ActionRequest

operationThreading

public SearchOperationThreading operationThreading()
Controls the the search operation threading model.


operationThreading

public SearchRequest operationThreading(SearchOperationThreading operationThreading)
Controls the the search operation threading model.


operationThreading

public SearchRequest operationThreading(java.lang.String operationThreading)
Sets the string representation of the operation threading model. Can be one of "no_threads", "single_thread" and "thread_per_shard".


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 to SearchType.DEFAULT.


searchType

public SearchRequest searchType(java.lang.String searchType)
                         throws ElasticSearchIllegalArgumentException
The a string representation search type to execute, defaults to SearchType.DEFAULT. Can be one of "dfs_query_then_fetch"/"dfsQueryThenFetch", "dfs_query_and_fetch"/"dfsQueryAndFetch", "query_then_fetch"/"queryThenFetch", and "query_and_fetch"/"queryAndFetch".

Throws:
ElasticSearchIllegalArgumentException

source

public SearchRequest source(SearchSourceBuilder sourceBuilder)
The source of the search request.


source

public SearchRequest source(java.lang.String source)
The source of the search request. Consider using either source(byte[]) or source(org.elasticsearch.search.builder.SearchSourceBuilder).


source

public SearchRequest source(java.util.Map source)
The source of the search request in the form of a map.


source

public SearchRequest source(XContentBuilder builder)

source

public SearchRequest source(byte[] source)
The search source to execute.


source

public SearchRequest source(byte[] source,
                            int offset,
                            int length)
The search source to execute.


source

public SearchRequest source(byte[] source,
                            int offset,
                            int length,
                            boolean unsafe)
The search source to execute.


source

public byte[] source()
The search source to execute.


sourceOffset

public int sourceOffset()

sourceLength

public int sourceLength()

extraSource

public SearchRequest extraSource(SearchSourceBuilder sourceBuilder)
Allows to provide additional source that will be used as well.


extraSource

public SearchRequest extraSource(java.util.Map extraSource)

extraSource

public SearchRequest extraSource(XContentBuilder builder)

extraSource

public SearchRequest extraSource(java.lang.String source)
Allows to provide additional source that will use used as well.


extraSource

public SearchRequest extraSource(byte[] source)
Allows to provide additional source that will be used as well.


extraSource

public SearchRequest extraSource(byte[] source,
                                 int offset,
                                 int length)
Allows to provide additional source that will be used as well.


extraSource

public SearchRequest extraSource(byte[] source,
                                 int offset,
                                 int length,
                                 boolean unsafe)
Allows to provide additional source that will be used as well.


extraSource

public byte[] extraSource()
Additional search source to execute.


extraSourceOffset

public int extraSourceOffset()

extraSourceLength

public int extraSourceLength()

searchType

public SearchType searchType()
The tye of search to execute.


indices

public java.lang.String[] indices()
The indices


queryHint

public SearchRequest queryHint(java.lang.String queryHint)
A query hint to optionally later be used when routing the request.


queryHint

public java.lang.String queryHint()
A query hint to optionally later be used when routing the request.


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.


timeout

public TimeValue timeout()
An optional timeout to control how long search is allowed to take.


timeout

public SearchRequest timeout(TimeValue timeout)
An optional timeout to control how long search is allowed to take.


timeout

public SearchRequest timeout(java.lang.String timeout)
An optional timeout to control how long search is allowed to take.


readFrom

public void readFrom(StreamInput in)
              throws java.io.IOException
Specified by:
readFrom in interface Streamable
Throws:
java.io.IOException

writeTo

public void writeTo(StreamOutput out)
             throws java.io.IOException
Specified by:
writeTo in interface Streamable
Throws:
java.io.IOException