org.elasticsearch.search.builder
Class SearchSourceBuilder

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

public class SearchSourceBuilder
extends 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
 BytesReference buildAsBytes()
           
 BytesReference buildAsBytes(XContentType contentType)
           
 SearchSourceBuilder explain(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 facets(byte[] facetsBinary)
          Sets a raw (xcontent / json) facets.
 SearchSourceBuilder facets(byte[] facetsBinary, int facetBinaryOffset, int facetBinaryLength)
          Sets a raw (xcontent / json) facets.
 SearchSourceBuilder facets(BytesReference facetsBinary)
          Sets a raw (xcontent / json) facets.
 SearchSourceBuilder facets(Map facets)
          Sets a raw (xcontent / json) facets.
 SearchSourceBuilder facets(XContentBuilder facets)
          Sets a raw (xcontent / json) facets.
 SearchSourceBuilder field(String name)
          Adds a field to load and return (note, it must be stored) as part of the search request.
 SearchSourceBuilder fields(List<String> fields)
          Sets the fields to load and return as part of the search request.
 SearchSourceBuilder fields(String... fields)
          Adds the fields to load and return as part of the search request.
 SearchSourceBuilder filter(byte[] filter)
          Sets a filter on the query executed that only applies to the search query (and not facets for example).
 SearchSourceBuilder filter(byte[] filterBinary, int filterBinaryOffset, int filterBinaryLength)
          Sets a filter on the query executed that only applies to the search query (and not facets for example).
 SearchSourceBuilder filter(BytesReference filterBinary)
          Sets a filter on the query executed that only applies to the search query (and not facets for example).
 SearchSourceBuilder filter(FilterBuilder filter)
          Sets a filter on the query executed that only applies to the search query (and not facets for example).
 SearchSourceBuilder filter(Map filter)
          Constructs a new search source builder with a query from a map.
 SearchSourceBuilder filter(String filterString)
          Sets a filter on the query executed that only applies to the search query (and not facets for example).
 SearchSourceBuilder filter(XContentBuilder filter)
          Constructs a new search source builder with a query from a builder.
 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(String index, float indexBoost)
          Sets the boost a specific index will receive when the query is executeed against it.
 SearchSourceBuilder minScore(float minScore)
          Sets the minimum score below which docs will be filtered out.
 SearchSourceBuilder noFields()
          Sets no fields to be loaded, resulting in only id and type to be returned per field.
 SearchSourceBuilder partialField(String name, String[] includes, String[] excludes)
          Adds a partial field based on _source, with an "includes" and/or "excludes set which can include simple wildcard elements.
 SearchSourceBuilder partialField(String name, String include, String exclude)
          Adds a partial field based on _source, with an "include" and/or "exclude" set which can include simple wildcard elements.
 SearchSourceBuilder query(byte[] queryBinary)
          Constructs a new search source builder with a raw search query.
 SearchSourceBuilder query(byte[] queryBinary, int queryBinaryOffset, int queryBinaryLength)
          Constructs a new search source builder with a raw search query.
 SearchSourceBuilder query(BytesReference queryBinary)
          Constructs a new search source builder with a raw search query.
 SearchSourceBuilder query(Map query)
          Constructs a new search source builder with a query from a map.
 SearchSourceBuilder query(QueryBuilder query)
          Constructs a new search source builder with a search query.
 SearchSourceBuilder query(String queryString)
          Constructs a new search source builder with a raw search query.
 SearchSourceBuilder query(XContentBuilder query)
          Constructs a new search source builder with a query from a builder.
 SearchSourceBuilder scriptField(String name, String script)
          Adds a script field under the given name with the provided script.
 SearchSourceBuilder scriptField(String name, String script, Map<String,Object> params)
          Adds a script field.
 SearchSourceBuilder scriptField(String name, String lang, String script, Map<String,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(String name)
          Add a sort against the given field name.
 SearchSourceBuilder sort(String name, SortOrder order)
          Adds a sort against the given field name and the sort ordering.
 SearchSourceBuilder stats(String... statsGroups)
          The stats groups this request will be aggregated under.
 SearchSourceBuilder timeout(String timeout)
          An optional timeout to control how long search is allowed to take.
 SearchSourceBuilder timeout(TimeValue timeout)
          An optional timeout to control how long search is allowed to take.
 String toString()
           
 XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params)
           
 SearchSourceBuilder trackScores(boolean trackScores)
          Applies when sorting, and controls if scores will be tracked as well.
 SearchSourceBuilder version(Boolean version)
          Should each SearchHit be returned with a version associated with it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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(QueryBuilder 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(byte[] queryBinary,
                                 int queryBinaryOffset,
                                 int queryBinaryLength)
Constructs a new search source builder with a raw search query.


query

public SearchSourceBuilder query(BytesReference queryBinary)
Constructs a new search source builder with a raw search query.


query

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


query

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


query

public SearchSourceBuilder query(Map query)
Constructs a new search source builder with a query from a map.


filter

public SearchSourceBuilder filter(FilterBuilder filter)
Sets a filter on the query executed that only applies to the search query (and not facets for example).


filter

public SearchSourceBuilder filter(String filterString)
Sets a filter on the query executed that only applies to the search query (and not facets for example).


filter

public SearchSourceBuilder filter(byte[] filter)
Sets a filter on the query executed that only applies to the search query (and not facets for example).


filter

public SearchSourceBuilder filter(byte[] filterBinary,
                                  int filterBinaryOffset,
                                  int filterBinaryLength)
Sets a filter on the query executed that only applies to the search query (and not facets for example).


filter

public SearchSourceBuilder filter(BytesReference filterBinary)
Sets a filter on the query executed that only applies to the search query (and not facets for example).


filter

public SearchSourceBuilder filter(XContentBuilder filter)
Constructs a new search source builder with a query from a builder.


filter

public SearchSourceBuilder filter(Map filter)
Constructs a new search source builder with a query from a map.


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.


minScore

public SearchSourceBuilder minScore(float minScore)
Sets the minimum score below which docs will be filtered out.


explain

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


version

public SearchSourceBuilder version(Boolean version)
Should each SearchHit be returned with a version associated with it.


timeout

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


timeout

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


sort

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


trackScores

public SearchSourceBuilder trackScores(boolean trackScores)
Applies when sorting, and controls if scores will be tracked as well. Defaults to false.


facet

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


facets

public SearchSourceBuilder facets(byte[] facetsBinary)
Sets a raw (xcontent / json) facets.


facets

public SearchSourceBuilder facets(byte[] facetsBinary,
                                  int facetBinaryOffset,
                                  int facetBinaryLength)
Sets a raw (xcontent / json) facets.


facets

public SearchSourceBuilder facets(BytesReference facetsBinary)
Sets a raw (xcontent / json) facets.


facets

public SearchSourceBuilder facets(XContentBuilder facets)
Sets a raw (xcontent / json) facets.


facets

public SearchSourceBuilder facets(Map facets)
Sets a raw (xcontent / json) facets.


highlighter

public HighlightBuilder highlighter()

highlight

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


noFields

public SearchSourceBuilder noFields()
Sets no fields to be loaded, resulting in only id and type to be returned per field.


fields

public SearchSourceBuilder fields(List<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(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(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(String name,
                                       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(String name,
                                       String script,
                                       Map<String,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(String name,
                                       String lang,
                                       String script,
                                       Map<String,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:

partialField

public SearchSourceBuilder partialField(String name,
                                        @Nullable
                                        String include,
                                        @Nullable
                                        String exclude)
Adds a partial field based on _source, with an "include" and/or "exclude" set which can include simple wildcard elements.

Parameters:
name - The name of the field
include - An optional include (optionally wildcarded) pattern from _source
exclude - An optional exclude (optionally wildcarded) pattern from _source

partialField

public SearchSourceBuilder partialField(String name,
                                        @Nullable
                                        String[] includes,
                                        @Nullable
                                        String[] excludes)
Adds a partial field based on _source, with an "includes" and/or "excludes set which can include simple wildcard elements.

Parameters:
name - The name of the field
includes - An optional list of includes (optionally wildcarded) patterns from _source
excludes - An optional list of excludes (optionally wildcarded) patterns from _source

indexBoost

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

stats

public SearchSourceBuilder stats(String... statsGroups)
The stats groups this request will be aggregated under.


toString

public String toString()
Overrides:
toString in class Object

buildAsBytes

public BytesReference buildAsBytes()
                            throws SearchSourceBuilderException
Throws:
SearchSourceBuilderException

buildAsBytes

public BytesReference buildAsBytes(XContentType contentType)
                            throws SearchSourceBuilderException
Throws:
SearchSourceBuilderException

toXContent

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


Copyright © 2009-2012. All Rights Reserved.