org.elasticsearch.client.action.search
Class SearchRequestBuilder

java.lang.Object
  extended by org.elasticsearch.client.action.support.BaseRequestBuilder<SearchRequest,SearchResponse>
      extended by org.elasticsearch.client.action.search.SearchRequestBuilder
All Implemented Interfaces:
RequestBuilder<SearchRequest,SearchResponse>

public class SearchRequestBuilder
extends BaseRequestBuilder<SearchRequest,SearchResponse>

A search action request builder.


Field Summary
 
Fields inherited from class org.elasticsearch.client.action.support.BaseRequestBuilder
client, request
 
Constructor Summary
SearchRequestBuilder(Client client)
           
 
Method Summary
 SearchRequestBuilder addFacet(AbstractFacetBuilder facet)
          Adds a facet to the search operation.
 SearchRequestBuilder addField(java.lang.String field)
          Adds a field to load and return (note, it must be stored) as part of the search request.
 SearchRequestBuilder addFields(java.lang.String... fields)
          Adds the fields to load and return as part of the search request.
 SearchRequestBuilder addHighlightedField(java.lang.String name)
          Adds a field to be highlighted with default fragment size of 100 characters, and default number of fragments of 5.
 SearchRequestBuilder addHighlightedField(java.lang.String name, int fragmentSize)
          Adds a field to be highlighted with a provided fragment size (in characters), and default number of fragments of 5.
 SearchRequestBuilder addHighlightedField(java.lang.String name, int fragmentSize, int numberOfFragments)
          Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.
 SearchRequestBuilder addIndexBoost(java.lang.String index, float indexBoost)
          Sets the boost a specific index will receive when the query is executeed against it.
 SearchRequestBuilder addScriptField(java.lang.String name, java.lang.String script)
          Adds a script based field to load and return.
 SearchRequestBuilder addScriptField(java.lang.String name, java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> params)
          Adds a script based field to load and return.
 SearchRequestBuilder addScriptField(java.lang.String name, java.lang.String lang, java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> params)
          Adds a script based field to load and return.
 SearchRequestBuilder addSort(SortBuilder sort)
          Adds a generic sort builder.
 SearchRequestBuilder addSort(java.lang.String field, SortOrder order)
          Adds a sort against the given field name and the sort ordering.
protected  void doExecute(ActionListener<SearchResponse> listener)
           
 SearchSourceBuilder internalBuilder()
           
 SearchRequestBuilder setExplain(boolean explain)
          Should each SearchHit be returned with an explanation of the hit (ranking).
 SearchRequestBuilder setFrom(int from)
          From index to start the search from.
 SearchRequestBuilder setHighlighterOrder(java.lang.String order)
          The order of fragments per field.
 SearchRequestBuilder setHighlighterPostTags(java.lang.String... postTags)
          Explicitly set the post tags that will be used for highlighting.
 SearchRequestBuilder setHighlighterPreTags(java.lang.String... preTags)
          Explicitly set the pre tags that will be used for highlighting.
 SearchRequestBuilder setHighlighterTagsSchema(java.lang.String schemaName)
          Set a tag scheme that encapsulates a built in pre and post tags.
 SearchRequestBuilder setIndices(java.lang.String... indices)
          Sets the indices the search will be executed on.
 SearchRequestBuilder setListenerThreaded(boolean listenerThreaded)
          Should the listener be called on a separate thread if needed.
 SearchRequestBuilder setOperationThreading(SearchOperationThreading operationThreading)
          Controls the the search operation threading model.
 SearchRequestBuilder setOperationThreading(java.lang.String operationThreading)
          Sets the string representation of the operation threading model.
 SearchRequestBuilder setQuery(byte[] queryBinary)
          Constructs a new search source builder with a raw search query.
 SearchRequestBuilder setQuery(java.lang.String query)
          Constructs a new search source builder with a raw search query.
 SearchRequestBuilder setQuery(XContentQueryBuilder queryBuilder)
          Constructs a new search source builder with a search query.
 SearchRequestBuilder setQueryHint(java.lang.String queryHint)
          A query hint to optionally later be used when routing the request.
 SearchRequestBuilder setQueryParserName(java.lang.String queryParserName)
          An optional query parser name to use.
 SearchRequestBuilder setRouting(java.lang.String... routing)
          The routing values to control the shards that the search will be executed on.
 SearchRequestBuilder setRouting(java.lang.String routing)
          A comma separated list of routing values to control the shards the search will be executed on.
 SearchRequestBuilder setScroll(Scroll scroll)
          If set, will enable scrolling of the search request.
 SearchRequestBuilder setScroll(java.lang.String keepAlive)
          If set, will enable scrolling of the search request for the specified timeout.
 SearchRequestBuilder setScroll(TimeValue keepAlive)
          If set, will enable scrolling of the search request for the specified timeout.
 SearchRequestBuilder setSearchType(SearchType searchType)
          The search type to execute, defaults to SearchType.DEFAULT.
 SearchRequestBuilder setSearchType(java.lang.String searchType)
          The a string representation search type to execute, defaults to SearchType.DEFAULT.
 SearchRequestBuilder setSize(int size)
          The number of search hits to return.
 SearchRequestBuilder setTimeout(java.lang.String timeout)
          An optional timeout to control how long search is allowed to take.
 SearchRequestBuilder setTimeout(TimeValue timeout)
          An optional timeout to control how long search is allowed to take.
 SearchRequestBuilder setTypes(java.lang.String... types)
          The document types to execute the search against.
 
Methods inherited from class org.elasticsearch.client.action.support.BaseRequestBuilder
execute, execute, request
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SearchRequestBuilder

public SearchRequestBuilder(Client client)
Method Detail

setIndices

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


setTypes

public SearchRequestBuilder setTypes(java.lang.String... types)
The document types to execute the search against. Defaults to be executed against all types.


setSearchType

public SearchRequestBuilder setSearchType(SearchType searchType)
The search type to execute, defaults to SearchType.DEFAULT.


setSearchType

public SearchRequestBuilder setSearchType(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

setScroll

public SearchRequestBuilder setScroll(Scroll scroll)
If set, will enable scrolling of the search request.


setScroll

public SearchRequestBuilder setScroll(TimeValue keepAlive)
If set, will enable scrolling of the search request for the specified timeout.


setScroll

public SearchRequestBuilder setScroll(java.lang.String keepAlive)
If set, will enable scrolling of the search request for the specified timeout.


setTimeout

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


setTimeout

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


setQueryHint

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


setRouting

public SearchRequestBuilder setRouting(java.lang.String routing)
A comma separated list of routing values to control the shards the search will be executed on.


setRouting

public SearchRequestBuilder setRouting(java.lang.String... routing)
The routing values to control the shards that the search will be executed on.


setOperationThreading

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


setOperationThreading

public SearchRequestBuilder setOperationThreading(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".


setListenerThreaded

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


setQuery

public SearchRequestBuilder setQuery(XContentQueryBuilder queryBuilder)
Constructs a new search source builder with a search query.

See Also:
QueryBuilders

setQuery

public SearchRequestBuilder setQuery(java.lang.String query)
Constructs a new search source builder with a raw search query.


setQuery

public SearchRequestBuilder setQuery(byte[] queryBinary)
Constructs a new search source builder with a raw search query.


setFrom

public SearchRequestBuilder setFrom(int from)
From index to start the search from. Defaults to 0.


setSize

public SearchRequestBuilder setSize(int size)
The number of search hits to return. Defaults to 10.


setQueryParserName

public SearchRequestBuilder setQueryParserName(java.lang.String queryParserName)
An optional query parser name to use.


setExplain

public SearchRequestBuilder setExplain(boolean explain)
Should each SearchHit be returned with an explanation of the hit (ranking).


addIndexBoost

public SearchRequestBuilder addIndexBoost(java.lang.String index,
                                          float indexBoost)
Sets the boost a specific index will receive when the query is executeed against it.

Parameters:
index - The index to apply the boost against
indexBoost - The boost to apply to the index

addField

public SearchRequestBuilder addField(java.lang.String field)
Adds a field to load and return (note, it must be stored) as part of the search request. If none are specified, the source of the document will be return.


addScriptField

public SearchRequestBuilder addScriptField(java.lang.String name,
                                           java.lang.String script)
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 hit
script - The script to use

addScriptField

public SearchRequestBuilder addScriptField(java.lang.String name,
                                           java.lang.String script,
                                           java.util.Map<java.lang.String,java.lang.Object> params)
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 hit
script - The script to use
params - Parameters that the script can use.

addScriptField

public SearchRequestBuilder addScriptField(java.lang.String name,
                                           java.lang.String lang,
                                           java.lang.String script,
                                           java.util.Map<java.lang.String,java.lang.Object> params)
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 hit
lang - The language of the script
script - The script to use
params - Parameters that the script can use (can be null).

addSort

public SearchRequestBuilder addSort(java.lang.String field,
                                    SortOrder order)
Adds a sort against the given field name and the sort ordering.

Parameters:
field - The name of the field
order - The sort ordering

addSort

public SearchRequestBuilder addSort(SortBuilder sort)
Adds a generic sort builder.

See Also:
SortBuilders

addFields

public SearchRequestBuilder addFields(java.lang.String... fields)
Adds the fields to load and return as part of the search request. If none are specified, the source of the document will be returned.


addFacet

public SearchRequestBuilder addFacet(AbstractFacetBuilder facet)
Adds a facet to the search operation.


addHighlightedField

public SearchRequestBuilder addHighlightedField(java.lang.String name)
Adds a field to be highlighted with default fragment size of 100 characters, and default number of fragments of 5.

Parameters:
name - The field to highlight

addHighlightedField

public SearchRequestBuilder addHighlightedField(java.lang.String name,
                                                int fragmentSize)
Adds a field to be highlighted with a provided fragment size (in characters), and default number of fragments of 5.

Parameters:
name - The field to highlight
fragmentSize - The size of a fragment in characters

addHighlightedField

public SearchRequestBuilder addHighlightedField(java.lang.String name,
                                                int fragmentSize,
                                                int numberOfFragments)
Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.

Parameters:
name - The field to highlight
fragmentSize - The size of a fragment in characters
numberOfFragments - The (maximum) number of fragments

setHighlighterTagsSchema

public SearchRequestBuilder setHighlighterTagsSchema(java.lang.String schemaName)
Set a tag scheme that encapsulates a built in pre and post tags. The allows schemes are styled and default.

Parameters:
schemaName - The tag scheme name

setHighlighterPreTags

public SearchRequestBuilder setHighlighterPreTags(java.lang.String... preTags)
Explicitly set the pre tags that will be used for highlighting.


setHighlighterPostTags

public SearchRequestBuilder setHighlighterPostTags(java.lang.String... postTags)
Explicitly set the post tags that will be used for highlighting.


setHighlighterOrder

public SearchRequestBuilder setHighlighterOrder(java.lang.String order)
The order of fragments per field. By default, ordered by the order in the highlighted text. Can be score, which then it will be ordered by score of the fragments.


internalBuilder

public SearchSourceBuilder internalBuilder()

doExecute

protected void doExecute(ActionListener<SearchResponse> listener)
Specified by:
doExecute in class BaseRequestBuilder<SearchRequest,SearchResponse>