org.elasticsearch.search.builder
Class SearchSourceBuilder

java.lang.Object
  extended by org.elasticsearch.search.builder.SearchSourceBuilder
All Implemented Interfaces:
ToXContent

public class SearchSourceBuilder
extends java.lang.Object
implements ToXContent

A search source builder allowing to easily build search source. Simple construction using searchSource().

See Also:
SearchRequest.source(SearchSourceBuilder)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.MapParams, ToXContent.Params
 
Field Summary
 
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
 
Constructor Summary
SearchSourceBuilder()
          Constructs a new search source builder.
 
Method Summary
 byte[] buildAsBytes()
           
 byte[] buildAsBytes(XContentType contentType)
           
 FastByteArrayOutputStream buildAsUnsafeBytes(XContentType contentType)
           
 SearchSourceBuilder explain(java.lang.Boolean explain)
          Should each SearchHit be returned with an explanation of the hit (ranking).
 SearchSourceBuilder facet(AbstractFacetBuilder facet)
          Add a facet to perform as part of the search.
 SearchSourceBuilder field(java.lang.String name)
          Adds a field to load and return (note, it must be stored) as part of the search request.
 SearchSourceBuilder fields(java.util.List<java.lang.String> fields)
          Sets the fields to load and return as part of the search request.
 SearchSourceBuilder fields(java.lang.String... fields)
          Adds the fields to load and return as part of the search request.
 SearchSourceBuilder from(int from)
          From index to start the search from.
static HighlightBuilder highlight()
          A static factory method to construct new search highlights.
 SearchSourceBuilder highlight(HighlightBuilder highlightBuilder)
          Adds highlight to perform as part of the search.
 HighlightBuilder highlighter()
           
 SearchSourceBuilder indexBoost(java.lang.String index, float indexBoost)
          Sets the boost a specific index will receive when the query is executeed against it.
 SearchSourceBuilder query(byte[] queryBinary)
          Constructs a new search source builder with a raw search query.
 SearchSourceBuilder query(java.lang.String queryString)
          Constructs a new search source builder with a raw search query.
 SearchSourceBuilder query(XContentQueryBuilder query)
          Constructs a new search source builder with a search query.
 SearchSourceBuilder queryParserName(java.lang.String queryParserName)
          An optional query parser name to use.
 SearchSourceBuilder scriptField(java.lang.String name, java.lang.String script)
          Adds a script field under the given name with the provided script.
 SearchSourceBuilder scriptField(java.lang.String name, java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> params)
          Adds a script field.
 SearchSourceBuilder scriptField(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 field.
static SearchSourceBuilder searchSource()
          A static factory method to construct a new search source.
 SearchSourceBuilder size(int size)
          The number of search hits to return.
 SearchSourceBuilder sort(SortBuilder sort)
          Adds a sort builder.
 SearchSourceBuilder sort(java.lang.String name)
          Add a sort against the given field name.
 SearchSourceBuilder sort(java.lang.String name, SortOrder order)
          Adds a sort against the given field name and the sort ordering.
 void toXContent(XContentBuilder builder, ToXContent.Params params)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SearchSourceBuilder

public SearchSourceBuilder()
Constructs a new search source builder.

Method Detail

searchSource

public static SearchSourceBuilder searchSource()
A static factory method to construct a new search source.


highlight

public static HighlightBuilder highlight()
A static factory method to construct new search highlights.


query

public SearchSourceBuilder query(XContentQueryBuilder query)
Constructs a new search source builder with a search query.

See Also:
QueryBuilders

query

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


query

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


from

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


size

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


queryParserName

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


explain

public SearchSourceBuilder explain(java.lang.Boolean explain)
Should each SearchHit be returned with an explanation of the hit (ranking).


sort

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

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

sort

public SearchSourceBuilder sort(java.lang.String name)
Add a sort against the given field name.

Parameters:
name - The name of the field to sort by

sort

public SearchSourceBuilder sort(SortBuilder sort)
Adds a sort builder.


facet

public SearchSourceBuilder facet(AbstractFacetBuilder facet)
Add a facet to perform as part of the search.


highlighter

public HighlightBuilder highlighter()

highlight

public SearchSourceBuilder highlight(HighlightBuilder highlightBuilder)
Adds highlight to perform as part of the search.


fields

public SearchSourceBuilder fields(java.util.List<java.lang.String> fields)
Sets the fields to load and return as part of the search request. If none are specified, the source of the document will be returned.


fields

public SearchSourceBuilder fields(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.


field

public SearchSourceBuilder field(java.lang.String name)
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.


scriptField

public SearchSourceBuilder scriptField(java.lang.String name,
                                       java.lang.String script)
Adds a script field under the given name with the provided script.

Parameters:
name - The name of the field
script - The script

scriptField

public SearchSourceBuilder scriptField(java.lang.String name,
                                       java.lang.String script,
                                       java.util.Map<java.lang.String,java.lang.Object> params)
Adds a script field.

Parameters:
name - The name of the field
script - The script to execute
params - The script parameters

scriptField

public SearchSourceBuilder scriptField(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 field.

Parameters:
name - The name of the field
lang - The language of the script
script - The script to execute
params - The script parameters (can be null)
Returns:

indexBoost

public SearchSourceBuilder indexBoost(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

buildAsUnsafeBytes

public FastByteArrayOutputStream buildAsUnsafeBytes(XContentType contentType)
                                             throws SearchSourceBuilderException
Throws:
SearchSourceBuilderException

buildAsBytes

public byte[] buildAsBytes()
                    throws SearchSourceBuilderException
Throws:
SearchSourceBuilderException

buildAsBytes

public byte[] buildAsBytes(XContentType contentType)
                    throws SearchSourceBuilderException
Throws:
SearchSourceBuilderException

toXContent

public void toXContent(XContentBuilder builder,
                       ToXContent.Params params)
                throws java.io.IOException
Specified by:
toXContent in interface ToXContent
Throws:
java.io.IOException