org.elasticsearch.index.query.xcontent
Class QueryBuilders

java.lang.Object
  extended by org.elasticsearch.index.query.xcontent.QueryBuilders

public abstract class QueryBuilders
extends java.lang.Object

A static factory for simple "import static" usage.


Method Summary
static BoolQueryBuilder boolQuery()
          A Query that matches documents matching boolean combinations of other queries.
static ConstantScoreQueryBuilder constantScoreQuery(XContentFilterBuilder filterBuilder)
          A query that wraps a filter and simply returns a constant score equal to the query boost for every document in the filter.
static CustomBoostFactorQueryBuilder customBoostFactorQuery(XContentQueryBuilder queryBuilder)
          A query that simply applies the boost fact to the wrapped query (multiplies it).
static CustomScoreQueryBuilder customScoreQuery(XContentQueryBuilder queryBuilder)
          A query that allows to define a custom scoring script.
static DisMaxQueryBuilder disMaxQuery()
          A query that generates the union of documents produced by its sub-queries, and that scores each document with the maximum score for that document as produced by any sub-query, plus a tie breaking increment for any additional matching sub-queries.
static FieldMaskingSpanQueryBuilder fieldMaskingSpanQuery(XContentSpanQueryBuilder query, java.lang.String field)
           
static FieldQueryBuilder fieldQuery(java.lang.String name, boolean query)
          A query that executes the query string against a field.
static FieldQueryBuilder fieldQuery(java.lang.String name, double query)
          A query that executes the query string against a field.
static FieldQueryBuilder fieldQuery(java.lang.String name, float query)
          A query that executes the query string against a field.
static FieldQueryBuilder fieldQuery(java.lang.String name, int query)
          A query that executes the query string against a field.
static FieldQueryBuilder fieldQuery(java.lang.String name, long query)
          A query that executes the query string against a field.
static FieldQueryBuilder fieldQuery(java.lang.String name, java.lang.Object query)
          A query that executes the query string against a field.
static FieldQueryBuilder fieldQuery(java.lang.String name, java.lang.String query)
          A query that executes the query string against a field.
static FilteredQueryBuilder filtered(XContentQueryBuilder queryBuilder, XContentFilterBuilder filterBuilder)
          Deprecated. Use filteredQuery instead (rename)
static FilteredQueryBuilder filteredQuery(XContentQueryBuilder queryBuilder, XContentFilterBuilder filterBuilder)
          A query that applies a filter to the results of another query.
static FuzzyLikeThisFieldQueryBuilder fuzzyLikeThisFieldQuery(java.lang.String name)
          A fuzzy like this query that finds documents that are "like" the provided FuzzyLikeThisFieldQueryBuilder.likeText(String).
static FuzzyLikeThisQueryBuilder fuzzyLikeThisQuery()
          A fuzzy like this query that finds documents that are "like" the provided FuzzyLikeThisQueryBuilder.likeText(String) which is checked against the "_all" field.
static FuzzyLikeThisQueryBuilder fuzzyLikeThisQuery(java.lang.String... fields)
          A fuzzy like this query that finds documents that are "like" the provided FuzzyLikeThisQueryBuilder.likeText(String) which is checked against the fields the query is constructed with.
static FuzzyQueryBuilder fuzzyQuery(java.lang.String name, java.lang.String value)
          A Query that matches documents using fuzzy query.
static MatchAllQueryBuilder matchAllQuery()
          A query that match on all documents.
static MoreLikeThisFieldQueryBuilder moreLikeThisFieldQuery(java.lang.String name)
          A more like this query that runs against a specific field.
static MoreLikeThisQueryBuilder moreLikeThisQuery()
          A more like this query that finds documents that are "like" the provided MoreLikeThisQueryBuilder.likeText(String) which is checked against the "_all" field.
static MoreLikeThisQueryBuilder moreLikeThisQuery(java.lang.String... fields)
          A more like this query that finds documents that are "like" the provided MoreLikeThisQueryBuilder.likeText(String) which is checked against the fields the query is constructed with.
static PrefixQueryBuilder prefixQuery(java.lang.String name, java.lang.String prefix)
          A Query that matches documents containing terms with a specified prefix.
static QueryStringQueryBuilder queryString(java.lang.String queryString)
          A query that parses a query string and runs it.
static RangeQueryBuilder rangeQuery(java.lang.String name)
          A Query that matches documents within an range of terms.
static SpanFirstQueryBuilder spanFirstQuery(XContentSpanQueryBuilder match, int end)
           
static SpanNearQueryBuilder spanNearQuery()
           
static SpanNotQueryBuilder spanNotQuery()
           
static SpanOrQueryBuilder spanOrQuery()
           
static SpanTermQueryBuilder spanTermQuery(java.lang.String name, double value)
           
static SpanTermQueryBuilder spanTermQuery(java.lang.String name, float value)
           
static SpanTermQueryBuilder spanTermQuery(java.lang.String name, int value)
           
static SpanTermQueryBuilder spanTermQuery(java.lang.String name, long value)
           
static SpanTermQueryBuilder spanTermQuery(java.lang.String name, java.lang.String value)
           
static TermQueryBuilder termQuery(java.lang.String name, boolean value)
          A Query that matches documents containing a term.
static TermQueryBuilder termQuery(java.lang.String name, double value)
          A Query that matches documents containing a term.
static TermQueryBuilder termQuery(java.lang.String name, float value)
          A Query that matches documents containing a term.
static TermQueryBuilder termQuery(java.lang.String name, int value)
          A Query that matches documents containing a term.
static TermQueryBuilder termQuery(java.lang.String name, long value)
          A Query that matches documents containing a term.
static TermQueryBuilder termQuery(java.lang.String name, java.lang.Object value)
          A Query that matches documents containing a term.
static TermQueryBuilder termQuery(java.lang.String name, java.lang.String value)
          A Query that matches documents containing a term.
static WildcardQueryBuilder wildcardQuery(java.lang.String name, java.lang.String query)
          Implements the wildcard search query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

matchAllQuery

public static MatchAllQueryBuilder matchAllQuery()
A query that match on all documents.


disMaxQuery

public static DisMaxQueryBuilder disMaxQuery()
A query that generates the union of documents produced by its sub-queries, and that scores each document with the maximum score for that document as produced by any sub-query, plus a tie breaking increment for any additional matching sub-queries.


termQuery

public static TermQueryBuilder termQuery(java.lang.String name,
                                         java.lang.String value)
A Query that matches documents containing a term.

Parameters:
name - The name of the field
value - The value of the term

termQuery

public static TermQueryBuilder termQuery(java.lang.String name,
                                         int value)
A Query that matches documents containing a term.

Parameters:
name - The name of the field
value - The value of the term

termQuery

public static TermQueryBuilder termQuery(java.lang.String name,
                                         long value)
A Query that matches documents containing a term.

Parameters:
name - The name of the field
value - The value of the term

termQuery

public static TermQueryBuilder termQuery(java.lang.String name,
                                         float value)
A Query that matches documents containing a term.

Parameters:
name - The name of the field
value - The value of the term

termQuery

public static TermQueryBuilder termQuery(java.lang.String name,
                                         double value)
A Query that matches documents containing a term.

Parameters:
name - The name of the field
value - The value of the term

termQuery

public static TermQueryBuilder termQuery(java.lang.String name,
                                         boolean value)
A Query that matches documents containing a term.

Parameters:
name - The name of the field
value - The value of the term

termQuery

public static TermQueryBuilder termQuery(java.lang.String name,
                                         java.lang.Object value)
A Query that matches documents containing a term.

Parameters:
name - The name of the field
value - The value of the term

fuzzyQuery

public static FuzzyQueryBuilder fuzzyQuery(java.lang.String name,
                                           java.lang.String value)
A Query that matches documents using fuzzy query.

Parameters:
name - The name of the field
value - The value of the term

fieldQuery

public static FieldQueryBuilder fieldQuery(java.lang.String name,
                                           java.lang.String query)
A query that executes the query string against a field. It is a simplified version of QueryStringQueryBuilder that simply runs against a single field.

Parameters:
name - The name of the field

fieldQuery

public static FieldQueryBuilder fieldQuery(java.lang.String name,
                                           int query)
A query that executes the query string against a field. It is a simplified version of QueryStringQueryBuilder that simply runs against a single field.

Parameters:
name - The name of the field
query - The query string

fieldQuery

public static FieldQueryBuilder fieldQuery(java.lang.String name,
                                           long query)
A query that executes the query string against a field. It is a simplified version of QueryStringQueryBuilder that simply runs against a single field.

Parameters:
name - The name of the field
query - The query string

fieldQuery

public static FieldQueryBuilder fieldQuery(java.lang.String name,
                                           float query)
A query that executes the query string against a field. It is a simplified version of QueryStringQueryBuilder that simply runs against a single field.

Parameters:
name - The name of the field
query - The query string

fieldQuery

public static FieldQueryBuilder fieldQuery(java.lang.String name,
                                           double query)
A query that executes the query string against a field. It is a simplified version of QueryStringQueryBuilder that simply runs against a single field.

Parameters:
name - The name of the field
query - The query string

fieldQuery

public static FieldQueryBuilder fieldQuery(java.lang.String name,
                                           boolean query)
A query that executes the query string against a field. It is a simplified version of QueryStringQueryBuilder that simply runs against a single field.

Parameters:
name - The name of the field
query - The query string

fieldQuery

public static FieldQueryBuilder fieldQuery(java.lang.String name,
                                           java.lang.Object query)
A query that executes the query string against a field. It is a simplified version of QueryStringQueryBuilder that simply runs against a single field.

Parameters:
name - The name of the field
query - The query string

prefixQuery

public static PrefixQueryBuilder prefixQuery(java.lang.String name,
                                             java.lang.String prefix)
A Query that matches documents containing terms with a specified prefix.

Parameters:
name - The name of the field
prefix - The prefix query

rangeQuery

public static RangeQueryBuilder rangeQuery(java.lang.String name)
A Query that matches documents within an range of terms.

Parameters:
name - The field name

wildcardQuery

public static WildcardQueryBuilder wildcardQuery(java.lang.String name,
                                                 java.lang.String query)
Implements the wildcard search query. Supported wildcards are *, which matches any character sequence (including the empty one), and ?, which matches any single character. Note this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards * or ?.

Parameters:
name - The field name
query - The wildcard query string

queryString

public static QueryStringQueryBuilder queryString(java.lang.String queryString)
A query that parses a query string and runs it. There are two modes that this operates. The first, when no field is added (using QueryStringQueryBuilder.field(String), will run the query once and non prefixed fields will use the QueryStringQueryBuilder.defaultField(String) set. The second, when one or more fields are added (using QueryStringQueryBuilder.field(String)), will run the parsed query against the provided fields, and combine them either using DisMax or a plain boolean query (see QueryStringQueryBuilder.useDisMax(boolean)).

Parameters:
queryString - The query string to run

boolQuery

public static BoolQueryBuilder boolQuery()
A Query that matches documents matching boolean combinations of other queries.


spanTermQuery

public static SpanTermQueryBuilder spanTermQuery(java.lang.String name,
                                                 java.lang.String value)

spanTermQuery

public static SpanTermQueryBuilder spanTermQuery(java.lang.String name,
                                                 int value)

spanTermQuery

public static SpanTermQueryBuilder spanTermQuery(java.lang.String name,
                                                 long value)

spanTermQuery

public static SpanTermQueryBuilder spanTermQuery(java.lang.String name,
                                                 float value)

spanTermQuery

public static SpanTermQueryBuilder spanTermQuery(java.lang.String name,
                                                 double value)

spanFirstQuery

public static SpanFirstQueryBuilder spanFirstQuery(XContentSpanQueryBuilder match,
                                                   int end)

spanNearQuery

public static SpanNearQueryBuilder spanNearQuery()

spanNotQuery

public static SpanNotQueryBuilder spanNotQuery()

spanOrQuery

public static SpanOrQueryBuilder spanOrQuery()

fieldMaskingSpanQuery

public static FieldMaskingSpanQueryBuilder fieldMaskingSpanQuery(XContentSpanQueryBuilder query,
                                                                 java.lang.String field)

filtered

public static FilteredQueryBuilder filtered(XContentQueryBuilder queryBuilder,
                                            XContentFilterBuilder filterBuilder)
Deprecated. Use filteredQuery instead (rename)

A query that applies a filter to the results of another query.

Parameters:
queryBuilder - The query to apply the filter to
filterBuilder - The filter to apply on the query

filteredQuery

public static FilteredQueryBuilder filteredQuery(XContentQueryBuilder queryBuilder,
                                                 XContentFilterBuilder filterBuilder)
A query that applies a filter to the results of another query.

Parameters:
queryBuilder - The query to apply the filter to
filterBuilder - The filter to apply on the query

constantScoreQuery

public static ConstantScoreQueryBuilder constantScoreQuery(XContentFilterBuilder filterBuilder)
A query that wraps a filter and simply returns a constant score equal to the query boost for every document in the filter.

Parameters:
filterBuilder - The filter to wrap in a constant score query

customBoostFactorQuery

public static CustomBoostFactorQueryBuilder customBoostFactorQuery(XContentQueryBuilder queryBuilder)
A query that simply applies the boost fact to the wrapped query (multiplies it).

Parameters:
queryBuilder - The query to apply the boost factor to.

customScoreQuery

public static CustomScoreQueryBuilder customScoreQuery(XContentQueryBuilder queryBuilder)
A query that allows to define a custom scoring script.

Parameters:
queryBuilder - The query to custom score

moreLikeThisQuery

public static MoreLikeThisQueryBuilder moreLikeThisQuery(java.lang.String... fields)
A more like this query that finds documents that are "like" the provided MoreLikeThisQueryBuilder.likeText(String) which is checked against the fields the query is constructed with.

Parameters:
fields - The fields to run the query against

moreLikeThisQuery

public static MoreLikeThisQueryBuilder moreLikeThisQuery()
A more like this query that finds documents that are "like" the provided MoreLikeThisQueryBuilder.likeText(String) which is checked against the "_all" field.


fuzzyLikeThisQuery

public static FuzzyLikeThisQueryBuilder fuzzyLikeThisQuery(java.lang.String... fields)
A fuzzy like this query that finds documents that are "like" the provided FuzzyLikeThisQueryBuilder.likeText(String) which is checked against the fields the query is constructed with.

Parameters:
fields - The fields to run the query against

fuzzyLikeThisQuery

public static FuzzyLikeThisQueryBuilder fuzzyLikeThisQuery()
A fuzzy like this query that finds documents that are "like" the provided FuzzyLikeThisQueryBuilder.likeText(String) which is checked against the "_all" field.


fuzzyLikeThisFieldQuery

public static FuzzyLikeThisFieldQueryBuilder fuzzyLikeThisFieldQuery(java.lang.String name)
A fuzzy like this query that finds documents that are "like" the provided FuzzyLikeThisFieldQueryBuilder.likeText(String).


moreLikeThisFieldQuery

public static MoreLikeThisFieldQueryBuilder moreLikeThisFieldQuery(java.lang.String name)
A more like this query that runs against a specific field.

Parameters:
name - The field name