java: QueryBuilders cleanup (add and deprecate)

Some QueryBuilders are missing or have a different naming than the other ones.

This patch is applied to branch 1.x and master (elasticsearch 1.5 and 2.0):

Added
-----

* `templateQuery(...)`
* `commonTermsQuery(...)`
* `queryStringQuery(...)`
* `simpleQueryStringQuery(...)`

Deprecated
----------

* `commonTerms(...)`
* `queryString(...)`
* `simpleQueryString(...)`
This commit is contained in:
David Pilato 2014-11-26 15:22:59 +01:00
parent 45c24b2eb3
commit 317192b647
24 changed files with 286 additions and 228 deletions

View File

@ -275,7 +275,7 @@ See {ref}/query-dsl-query-string-query.html[QueryString Query]
[source,java] [source,java]
-------------------------------------------------- --------------------------------------------------
QueryBuilder qb = queryString("+kimchy -elasticsearch"); <1> QueryBuilder qb = queryStringQuery("+kimchy -elasticsearch"); <1>
-------------------------------------------------- --------------------------------------------------
<1> text <1> text

View File

@ -23,8 +23,10 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
import org.elasticsearch.script.ScriptService;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
/** /**
* A static factory for simple "import static" usage. * A static factory for simple "import static" usage.
@ -48,13 +50,22 @@ public abstract class QueryBuilders {
return new MatchQueryBuilder(name, text).type(MatchQueryBuilder.Type.BOOLEAN); return new MatchQueryBuilder(name, text).type(MatchQueryBuilder.Type.BOOLEAN);
} }
/**
* @deprecated by commonTermsQuery(String, Object)
* Will be removed in elasticsearch 2.0.0
*/
@Deprecated
public static CommonTermsQueryBuilder commonTerms(String name, Object text) {
return commonTermsQuery(name, text);
}
/** /**
* Creates a common query for the provided field name and text. * Creates a common query for the provided field name and text.
* *
* @param name The field name. * @param name The field name.
* @param text The query text (to be analyzed). * @param text The query text (to be analyzed).
*/ */
public static CommonTermsQueryBuilder commonTerms(String name, Object text) { public static CommonTermsQueryBuilder commonTermsQuery(String name, Object text) {
return new CommonTermsQueryBuilder(name, text); return new CommonTermsQueryBuilder(name, text);
} }
@ -74,6 +85,7 @@ public abstract class QueryBuilders {
* @param name The field name. * @param name The field name.
* @param text The query text (to be analyzed). * @param text The query text (to be analyzed).
* @deprecated use {@link #textPhraseQuery(String, Object)} instead * @deprecated use {@link #textPhraseQuery(String, Object)} instead
* Will be removed in elasticsearch 2.0.0
*/ */
public static MatchQueryBuilder textPhrase(String name, Object text) { public static MatchQueryBuilder textPhrase(String name, Object text) {
return textPhraseQuery(name, text); return textPhraseQuery(name, text);
@ -106,6 +118,7 @@ public abstract class QueryBuilders {
* @param name The field name. * @param name The field name.
* @param text The query text (to be analyzed). * @param text The query text (to be analyzed).
* @deprecated use {@link #textPhrasePrefixQuery(String, Object)} instead * @deprecated use {@link #textPhrasePrefixQuery(String, Object)} instead
* Will be removed in elasticsearch 2.0.0
*/ */
public static MatchQueryBuilder textPhrasePrefix(String name, Object text) { public static MatchQueryBuilder textPhrasePrefix(String name, Object text) {
return textPhrasePrefixQuery(name, text); return textPhrasePrefixQuery(name, text);
@ -117,6 +130,7 @@ public abstract class QueryBuilders {
* @param name The field name. * @param name The field name.
* @param text The query text (to be analyzed). * @param text The query text (to be analyzed).
* @deprecated Use {@link #matchPhrasePrefixQuery(String, Object)} * @deprecated Use {@link #matchPhrasePrefixQuery(String, Object)}
* Will be removed in elasticsearch 2.0.0
*/ */
public static MatchQueryBuilder textPhrasePrefixQuery(String name, Object text) { public static MatchQueryBuilder textPhrasePrefixQuery(String name, Object text) {
return new MatchQueryBuilder(name, text).type(MatchQueryBuilder.Type.PHRASE_PREFIX); return new MatchQueryBuilder(name, text).type(MatchQueryBuilder.Type.PHRASE_PREFIX);
@ -285,6 +299,14 @@ public abstract class QueryBuilders {
return new RegexpQueryBuilder(name, regexp); return new RegexpQueryBuilder(name, regexp);
} }
/**
* @deprecated by queryStringQuery(String)
*/
@Deprecated
public static QueryStringQueryBuilder queryString(String queryString) {
return queryStringQuery(queryString);
}
/** /**
* A query that parses a query string and runs it. There are two modes that this operates. The first, * 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 {@link QueryStringQueryBuilder#field(String)}, will run the query once and non prefixed fields * when no field is added (using {@link QueryStringQueryBuilder#field(String)}, will run the query once and non prefixed fields
@ -294,17 +316,25 @@ public abstract class QueryBuilders {
* *
* @param queryString The query string to run * @param queryString The query string to run
*/ */
public static QueryStringQueryBuilder queryString(String queryString) { public static QueryStringQueryBuilder queryStringQuery(String queryString) {
return new QueryStringQueryBuilder(queryString); return new QueryStringQueryBuilder(queryString);
} }
/**
* @deprecated by simpleQueryStringQuery(String)
*/
@Deprecated
public static SimpleQueryStringBuilder simpleQueryString(String queryString) {
return simpleQueryStringQuery(queryString);
}
/** /**
* A query that acts similar to a query_string query, but won't throw * A query that acts similar to a query_string query, but won't throw
* exceptions for any weird string syntax. See * exceptions for any weird string syntax. See
* {@link org.apache.lucene.queryparser.XSimpleQueryParser} for the full * {@link org.apache.lucene.queryparser.XSimpleQueryParser} for the full
* supported syntax. * supported syntax.
*/ */
public static SimpleQueryStringBuilder simpleQueryString(String queryString) { public static SimpleQueryStringBuilder simpleQueryStringQuery(String queryString) {
return new SimpleQueryStringBuilder(queryString); return new SimpleQueryStringBuilder(queryString);
} }
@ -384,6 +414,7 @@ public abstract class QueryBuilders {
* @param queryBuilder The query to apply the filter to * @param queryBuilder The query to apply the filter to
* @param filterBuilder The filter to apply on the query * @param filterBuilder The filter to apply on the query
* @deprecated Use filteredQuery instead (rename) * @deprecated Use filteredQuery instead (rename)
* Will be removed in elasticsearch 2.0.0
*/ */
public static FilteredQueryBuilder filtered(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder) { public static FilteredQueryBuilder filtered(QueryBuilder queryBuilder, @Nullable FilterBuilder filterBuilder) {
return new FilteredQueryBuilder(queryBuilder, filterBuilder); return new FilteredQueryBuilder(queryBuilder, filterBuilder);
@ -632,6 +663,8 @@ public abstract class QueryBuilders {
* *
* @param name The field name * @param name The field name
* @param values The terms * @param values The terms
* @deprecated not used
* Will be removed in elasticsearch 2.0.0
*/ */
public static TermsQueryBuilder inQuery(String name, String... values) { public static TermsQueryBuilder inQuery(String name, String... values) {
return new TermsQueryBuilder(name, values); return new TermsQueryBuilder(name, values);
@ -642,6 +675,8 @@ public abstract class QueryBuilders {
* *
* @param name The field name * @param name The field name
* @param values The terms * @param values The terms
* @deprecated not used
* Will be removed in elasticsearch 2.0.0
*/ */
public static TermsQueryBuilder inQuery(String name, int... values) { public static TermsQueryBuilder inQuery(String name, int... values) {
return new TermsQueryBuilder(name, values); return new TermsQueryBuilder(name, values);
@ -652,6 +687,8 @@ public abstract class QueryBuilders {
* *
* @param name The field name * @param name The field name
* @param values The terms * @param values The terms
* @deprecated not used
* Will be removed in elasticsearch 2.0.0
*/ */
public static TermsQueryBuilder inQuery(String name, long... values) { public static TermsQueryBuilder inQuery(String name, long... values) {
return new TermsQueryBuilder(name, values); return new TermsQueryBuilder(name, values);
@ -662,6 +699,8 @@ public abstract class QueryBuilders {
* *
* @param name The field name * @param name The field name
* @param values The terms * @param values The terms
* @deprecated not used
* Will be removed in elasticsearch 2.0.0
*/ */
public static TermsQueryBuilder inQuery(String name, float... values) { public static TermsQueryBuilder inQuery(String name, float... values) {
return new TermsQueryBuilder(name, values); return new TermsQueryBuilder(name, values);
@ -672,6 +711,8 @@ public abstract class QueryBuilders {
* *
* @param name The field name * @param name The field name
* @param values The terms * @param values The terms
* @deprecated not used
* Will be removed in elasticsearch 2.0.0
*/ */
public static TermsQueryBuilder inQuery(String name, double... values) { public static TermsQueryBuilder inQuery(String name, double... values) {
return new TermsQueryBuilder(name, values); return new TermsQueryBuilder(name, values);
@ -682,6 +723,8 @@ public abstract class QueryBuilders {
* *
* @param name The field name * @param name The field name
* @param values The terms * @param values The terms
* @deprecated not used
* Will be removed in elasticsearch 2.0.0
*/ */
public static TermsQueryBuilder inQuery(String name, Object... values) { public static TermsQueryBuilder inQuery(String name, Object... values) {
return new TermsQueryBuilder(name, values); return new TermsQueryBuilder(name, values);
@ -692,6 +735,8 @@ public abstract class QueryBuilders {
* *
* @param name The field name * @param name The field name
* @param values The terms * @param values The terms
* @deprecated not used
* Will be removed in elasticsearch 2.0.0
*/ */
public static TermsQueryBuilder inQuery(String name, Collection<?> values) { public static TermsQueryBuilder inQuery(String name, Collection<?> values) {
return new TermsQueryBuilder(name, values); return new TermsQueryBuilder(name, values);
@ -734,6 +779,20 @@ public abstract class QueryBuilders {
return new GeoShapeQueryBuilder(name, indexedShapeId, indexedShapeType); return new GeoShapeQueryBuilder(name, indexedShapeId, indexedShapeType);
} }
/**
* Facilitates creating template query requests using an inline script
*/
public static TemplateQueryBuilder templateQuery(String template, Map<String, Object> vars) {
return new TemplateQueryBuilder(template, vars);
}
/**
* Facilitates creating template query requests
*/
public static TemplateQueryBuilder templateQuery(String template, ScriptService.ScriptType templateType, Map<String, Object> vars) {
return new TemplateQueryBuilder(template, templateType, vars);
}
private QueryBuilders() { private QueryBuilders() {
} }

View File

@ -70,7 +70,7 @@ public class RestExplainAction extends BaseRestHandler {
} else if (sourceString != null) { } else if (sourceString != null) {
explainRequest.source(new BytesArray(request.param("source")), false); explainRequest.source(new BytesArray(request.param("source")), false);
} else if (queryString != null) { } else if (queryString != null) {
QueryStringQueryBuilder queryStringBuilder = QueryBuilders.queryString(queryString); QueryStringQueryBuilder queryStringBuilder = QueryBuilders.queryStringQuery(queryString);
queryStringBuilder.defaultField(request.param("df")); queryStringBuilder.defaultField(request.param("df"));
queryStringBuilder.analyzer(request.param("analyzer")); queryStringBuilder.analyzer(request.param("analyzer"));
queryStringBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false)); queryStringBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));

View File

@ -125,7 +125,7 @@ public class RestSearchAction extends BaseRestHandler {
SearchSourceBuilder searchSourceBuilder = null; SearchSourceBuilder searchSourceBuilder = null;
String queryString = request.param("q"); String queryString = request.param("q");
if (queryString != null) { if (queryString != null) {
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryString(queryString); QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
queryBuilder.defaultField(request.param("df")); queryBuilder.defaultField(request.param("df"));
queryBuilder.analyzer(request.param("analyzer")); queryBuilder.analyzer(request.param("analyzer"));
queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false)); queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));

View File

@ -89,7 +89,7 @@ public class RestActions {
if (queryString == null) { if (queryString == null) {
return null; return null;
} }
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryString(queryString); QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
queryBuilder.defaultField(request.param("df")); queryBuilder.defaultField(request.param("df"));
queryBuilder.analyzer(request.param("analyzer")); queryBuilder.analyzer(request.param("analyzer"));
String defaultOperator = request.param("default_operator"); String defaultOperator = request.param("default_operator");

View File

@ -90,7 +90,7 @@ public class BenchmarkTestUtil {
QUERY_STRING { QUERY_STRING {
@Override @Override
QueryBuilder getQuery() { QueryBuilder getQuery() {
return QueryBuilders.queryString( return QueryBuilders.queryStringQuery(
randomAsciiOfLengthBetween(1, 3)); randomAsciiOfLengthBetween(1, 3));
} }
}, },

View File

@ -432,7 +432,7 @@ public class BasicBackwardsCompatibilityTest extends ElasticsearchBackwardsCompa
countResponse = client().prepareCount().setQuery(constantScoreQuery(existsFilter("field1"))).get(); countResponse = client().prepareCount().setQuery(constantScoreQuery(existsFilter("field1"))).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(queryString("_exists_:field1")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("_exists_:field1")).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(filteredQuery(matchAllQuery(), existsFilter("field2"))).get(); countResponse = client().prepareCount().setQuery(filteredQuery(matchAllQuery(), existsFilter("field2"))).get();
@ -458,7 +458,7 @@ public class BasicBackwardsCompatibilityTest extends ElasticsearchBackwardsCompa
countResponse = client().prepareCount().setQuery(constantScoreQuery(missingFilter("field1"))).get(); countResponse = client().prepareCount().setQuery(constantScoreQuery(missingFilter("field1"))).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(queryString("_missing_:field1")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("_missing_:field1")).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
// wildcard check // wildcard check

View File

@ -88,33 +88,33 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"), client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"),
client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") ); client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") );
CountResponse countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).get(); CountResponse countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).get();
assertHitCount(countResponse, 3l); assertHitCount(countResponse, 3l);
countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get(); countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
// Default // Default
countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3)).get(); countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the quick brown").cutoffFrequency(3)).get();
assertHitCount(countResponse, 3l); assertHitCount(countResponse, 3l);
countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the huge fox").lowFreqMinimumShouldMatch("2")).get(); countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the huge fox").lowFreqMinimumShouldMatch("2")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("3")).get(); countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("3")).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("4")).get(); countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("4")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setSource(new BytesArray("{ \"query\" : { \"common\" : { \"field1\" : { \"query\" : \"the lazy fox brown\", \"cutoff_frequency\" : 1, \"minimum_should_match\" : { \"high_freq\" : 4 } } } } }").array()).get(); countResponse = client().prepareCount().setSource(new BytesArray("{ \"query\" : { \"common\" : { \"field1\" : { \"query\" : \"the lazy fox brown\", \"cutoff_frequency\" : 1, \"minimum_should_match\" : { \"high_freq\" : 4 } } } } }").array()).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
// Default // Default
countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the lazy fox brown").cutoffFrequency(1)).get(); countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3).analyzer("standard")).get(); countResponse = client().prepareCount().setQuery(QueryBuilders.commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).analyzer("standard")).get();
assertHitCount(countResponse, 3l); assertHitCount(countResponse, 3l);
// standard drops "the" since its a stopword // standard drops "the" since its a stopword
@ -141,19 +141,19 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get(); client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get();
refresh(); refresh();
CountResponse countResponse = client().prepareCount().setQuery(queryString("value*").analyzeWildcard(true)).get(); CountResponse countResponse = client().prepareCount().setQuery(queryStringQuery("value*").analyzeWildcard(true)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("*ue*").analyzeWildcard(true)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("*ue*").analyzeWildcard(true)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("*ue_1").analyzeWildcard(true)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("*ue_1").analyzeWildcard(true)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("val*e_1").analyzeWildcard(true)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("val*e_1").analyzeWildcard(true)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("v?l*e?1").analyzeWildcard(true)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("v?l*e?1").analyzeWildcard(true)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
} }
@ -164,17 +164,17 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get(); client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get();
refresh(); refresh();
CountResponse countResponse = client().prepareCount().setQuery(queryString("VALUE_3~1").lowercaseExpandedTerms(true)).get(); CountResponse countResponse = client().prepareCount().setQuery(queryStringQuery("VALUE_3~1").lowercaseExpandedTerms(true)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("VALUE_3~1").lowercaseExpandedTerms(false)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("VALUE_3~1").lowercaseExpandedTerms(false)).get();
assertHitCount(countResponse, 0l); assertHitCount(countResponse, 0l);
countResponse = client().prepareCount().setQuery(queryString("ValUE_*").lowercaseExpandedTerms(true)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("ValUE_*").lowercaseExpandedTerms(true)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("vAl*E_1")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("vAl*E_1")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("[VALUE_1 TO VALUE_3]")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("[VALUE_1 TO VALUE_3]")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("[VALUE_1 TO VALUE_3]").lowercaseExpandedTerms(false)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("[VALUE_1 TO VALUE_3]").lowercaseExpandedTerms(false)).get();
assertHitCount(countResponse, 0l); assertHitCount(countResponse, 0l);
} }
@ -195,13 +195,13 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get(); client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get();
refresh(); refresh();
CountResponse countResponse = client().prepareCount().setQuery(queryString("past:[now-2M/d TO now/d]")).get(); CountResponse countResponse = client().prepareCount().setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("future:[now/d TO now+2M/d]").lowercaseExpandedTerms(false)).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("future:[now/d TO now+2M/d]").lowercaseExpandedTerms(false)).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount("test").setQuery(queryString("future:[now/D TO now+2M/d]").lowercaseExpandedTerms(false)).get(); countResponse = client().prepareCount("test").setQuery(queryStringQuery("future:[now/D TO now+2M/d]").lowercaseExpandedTerms(false)).get();
//D is an unsupported unit in date math //D is an unsupported unit in date math
assertThat(countResponse.getSuccessfulShards(), equalTo(0)); assertThat(countResponse.getSuccessfulShards(), equalTo(0));
assertThat(countResponse.getFailedShards(), equalTo(test.numPrimaries)); assertThat(countResponse.getFailedShards(), equalTo(test.numPrimaries));
@ -316,7 +316,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
countResponse = client().prepareCount().setQuery(constantScoreQuery(existsFilter("field1"))).get(); countResponse = client().prepareCount().setQuery(constantScoreQuery(existsFilter("field1"))).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(queryString("_exists_:field1")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("_exists_:field1")).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(filteredQuery(matchAllQuery(), existsFilter("field2"))).get(); countResponse = client().prepareCount().setQuery(filteredQuery(matchAllQuery(), existsFilter("field2"))).get();
@ -342,7 +342,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
countResponse = client().prepareCount().setQuery(constantScoreQuery(missingFilter("field1"))).get(); countResponse = client().prepareCount().setQuery(constantScoreQuery(missingFilter("field1"))).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(queryString("_missing_:field1")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("_missing_:field1")).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
// wildcard check // wildcard check
@ -537,13 +537,13 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get(); client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get();
refresh(); refresh();
CountResponse countResponse = client().prepareCount().setQuery(queryString("str:kimcy~1")).get(); CountResponse countResponse = client().prepareCount().setQuery(queryStringQuery("str:kimcy~1")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("num:11~1")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("num:11~1")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("date:2012-02-02~1d")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("date:2012-02-02~1d")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
} }
@ -554,25 +554,25 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get(); client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get();
refresh(); refresh();
CountResponse countResponse = client().prepareCount().setQuery(queryString("num:>19")).get(); CountResponse countResponse = client().prepareCount().setQuery(queryStringQuery("num:>19")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("num:>20")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("num:>20")).get();
assertHitCount(countResponse, 0l); assertHitCount(countResponse, 0l);
countResponse = client().prepareCount().setQuery(queryString("num:>=20")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("num:>=20")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("num:>11")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("num:>11")).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(queryString("num:<20")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("num:<20")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(queryString("num:<=20")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("num:<=20")).get();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount().setQuery(queryString("+num:>11 +num:<20")).get(); countResponse = client().prepareCount().setQuery(queryStringQuery("+num:>11 +num:<20")).get();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
} }

View File

@ -93,14 +93,14 @@ public class SimpleCountTests extends ElasticsearchIntegrationTest {
CountResponse countResponse = client().prepareCount().setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet(); CountResponse countResponse = client().prepareCount().setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(QueryBuilders.queryString("_id:XXX1")).execute().actionGet(); countResponse = client().prepareCount().setQuery(QueryBuilders.queryStringQuery("_id:XXX1")).execute().actionGet();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
// id is not index, but we can automatically support prefix as well // id is not index, but we can automatically support prefix as well
countResponse = client().prepareCount().setQuery(QueryBuilders.prefixQuery("_id", "XXX")).execute().actionGet(); countResponse = client().prepareCount().setQuery(QueryBuilders.prefixQuery("_id", "XXX")).execute().actionGet();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
countResponse = client().prepareCount().setQuery(QueryBuilders.queryString("_id:XXX*").lowercaseExpandedTerms(false)).execute().actionGet(); countResponse = client().prepareCount().setQuery(QueryBuilders.queryStringQuery("_id:XXX*").lowercaseExpandedTerms(false)).execute().actionGet();
assertHitCount(countResponse, 1l); assertHitCount(countResponse, 1l);
} }
@ -114,7 +114,7 @@ public class SimpleCountTests extends ElasticsearchIntegrationTest {
CountResponse countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet(); CountResponse countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
countResponse = client().prepareCount("test").setQuery(QueryBuilders.queryString("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet(); countResponse = client().prepareCount("test").setQuery(QueryBuilders.queryStringQuery("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet();
assertHitCount(countResponse, 2l); assertHitCount(countResponse, 2l);
} }

View File

@ -89,13 +89,13 @@ public class SimpleExistsTests extends ElasticsearchIntegrationTest {
ExistsResponse existsResponse = client().prepareExists().setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet(); ExistsResponse existsResponse = client().prepareExists().setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
assertExists(existsResponse, true); assertExists(existsResponse, true);
existsResponse = client().prepareExists().setQuery(QueryBuilders.queryString("_id:XXX1")).execute().actionGet(); existsResponse = client().prepareExists().setQuery(QueryBuilders.queryStringQuery("_id:XXX1")).execute().actionGet();
assertExists(existsResponse, true); assertExists(existsResponse, true);
existsResponse = client().prepareExists().setQuery(QueryBuilders.prefixQuery("_id", "XXX")).execute().actionGet(); existsResponse = client().prepareExists().setQuery(QueryBuilders.prefixQuery("_id", "XXX")).execute().actionGet();
assertExists(existsResponse, true); assertExists(existsResponse, true);
existsResponse = client().prepareExists().setQuery(QueryBuilders.queryString("_id:XXX*").lowercaseExpandedTerms(false)).execute().actionGet(); existsResponse = client().prepareExists().setQuery(QueryBuilders.queryStringQuery("_id:XXX*").lowercaseExpandedTerms(false)).execute().actionGet();
assertExists(existsResponse, true); assertExists(existsResponse, true);
} }
@ -109,7 +109,7 @@ public class SimpleExistsTests extends ElasticsearchIntegrationTest {
ExistsResponse existsResponse = client().prepareExists("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet(); ExistsResponse existsResponse = client().prepareExists("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet();
assertExists(existsResponse, true); assertExists(existsResponse, true);
existsResponse = client().prepareExists("test").setQuery(QueryBuilders.queryString("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet(); existsResponse = client().prepareExists("test").setQuery(QueryBuilders.queryStringQuery("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet();
assertExists(existsResponse, true); assertExists(existsResponse, true);
} }
@ -124,7 +124,7 @@ public class SimpleExistsTests extends ElasticsearchIntegrationTest {
ExistsResponse existsResponse = client().prepareExists("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-07||+2d").lte("2010-01-21||+2d")).execute().actionGet(); ExistsResponse existsResponse = client().prepareExists("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-07||+2d").lte("2010-01-21||+2d")).execute().actionGet();
assertExists(existsResponse, false); assertExists(existsResponse, false);
existsResponse = client().prepareExists("test").setQuery(QueryBuilders.queryString("_id:XXY*").lowercaseExpandedTerms(false)).execute().actionGet(); existsResponse = client().prepareExists("test").setQuery(QueryBuilders.queryStringQuery("_id:XXY*").lowercaseExpandedTerms(false)).execute().actionGet();
assertExists(existsResponse, false); assertExists(existsResponse, false);
} }

View File

@ -40,7 +40,7 @@ import java.io.ByteArrayOutputStream;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.queryString; import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
@ -262,7 +262,7 @@ public class ExplainActionTests extends ElasticsearchIntegrationTest {
refresh(); refresh();
ExplainResponse explainResponse = client().prepareExplain("test", "type", "1").setQuery(queryString("past:[now-2M/d TO now/d]")).get(); ExplainResponse explainResponse = client().prepareExplain("test", "type", "1").setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).get();
assertThat(explainResponse.isExists(), equalTo(true)); assertThat(explainResponse.isExists(), equalTo(true));
assertThat(explainResponse.isMatch(), equalTo(true)); assertThat(explainResponse.isMatch(), equalTo(true));
} }

View File

@ -120,7 +120,7 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
@Test @Test
public void testQueryStringBuilder() throws Exception { public void testQueryStringBuilder() throws Exception {
IndexQueryParserService queryParser = queryParser(); IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(queryString("test").defaultField("content").phraseSlop(1)).query(); Query parsedQuery = queryParser.parse(queryStringQuery("test").defaultField("content").phraseSlop(1)).query();
assertThat(parsedQuery, instanceOf(TermQuery.class)); assertThat(parsedQuery, instanceOf(TermQuery.class));
TermQuery termQuery = (TermQuery) parsedQuery; TermQuery termQuery = (TermQuery) parsedQuery;
@ -140,7 +140,7 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
@Test @Test
public void testQueryStringBoostsBuilder() throws Exception { public void testQueryStringBoostsBuilder() throws Exception {
IndexQueryParserService queryParser = queryParser(); IndexQueryParserService queryParser = queryParser();
QueryStringQueryBuilder builder = queryString("field:boosted^2"); QueryStringQueryBuilder builder = queryStringQuery("field:boosted^2");
Query parsedQuery = queryParser.parse(builder).query(); Query parsedQuery = queryParser.parse(builder).query();
assertThat(parsedQuery, instanceOf(TermQuery.class)); assertThat(parsedQuery, instanceOf(TermQuery.class));
assertThat(((TermQuery) parsedQuery).getTerm(), equalTo(new Term("field", "boosted"))); assertThat(((TermQuery) parsedQuery).getTerm(), equalTo(new Term("field", "boosted")));
@ -149,7 +149,7 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
parsedQuery = queryParser.parse(builder).query(); parsedQuery = queryParser.parse(builder).query();
assertThat(parsedQuery.getBoost(), equalTo(4.0f)); assertThat(parsedQuery.getBoost(), equalTo(4.0f));
builder = queryString("((field:boosted^2) AND (field:foo^1.5))^3"); builder = queryStringQuery("((field:boosted^2) AND (field:foo^1.5))^3");
parsedQuery = queryParser.parse(builder).query(); parsedQuery = queryParser.parse(builder).query();
assertThat(parsedQuery, instanceOf(BooleanQuery.class)); assertThat(parsedQuery, instanceOf(BooleanQuery.class));
assertThat(assertBooleanSubQuery(parsedQuery, TermQuery.class, 0).getTerm(), equalTo(new Term("field", "boosted"))); assertThat(assertBooleanSubQuery(parsedQuery, TermQuery.class, 0).getTerm(), equalTo(new Term("field", "boosted")));
@ -165,7 +165,7 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
@Test @Test
public void testQueryStringFields1Builder() throws Exception { public void testQueryStringFields1Builder() throws Exception {
IndexQueryParserService queryParser = queryParser(); IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(queryString("test").field("content").field("name").useDisMax(false)).query(); Query parsedQuery = queryParser.parse(queryStringQuery("test").field("content").field("name").useDisMax(false)).query();
assertThat(parsedQuery, instanceOf(BooleanQuery.class)); assertThat(parsedQuery, instanceOf(BooleanQuery.class));
BooleanQuery bQuery = (BooleanQuery) parsedQuery; BooleanQuery bQuery = (BooleanQuery) parsedQuery;
assertThat(bQuery.clauses().size(), equalTo(2)); assertThat(bQuery.clauses().size(), equalTo(2));
@ -201,7 +201,7 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
@Test @Test
public void testQueryStringFields2Builder() throws Exception { public void testQueryStringFields2Builder() throws Exception {
IndexQueryParserService queryParser = queryParser(); IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(queryString("test").field("content").field("name").useDisMax(true)).query(); Query parsedQuery = queryParser.parse(queryStringQuery("test").field("content").field("name").useDisMax(true)).query();
assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class));
DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) parsedQuery; DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) parsedQuery;
List<Query> disjuncts = disMaxQuery.getDisjuncts(); List<Query> disjuncts = disMaxQuery.getDisjuncts();
@ -224,7 +224,7 @@ public class SimpleIndexQueryParserTests extends ElasticsearchSingleNodeTest {
@Test @Test
public void testQueryStringFields3Builder() throws Exception { public void testQueryStringFields3Builder() throws Exception {
IndexQueryParserService queryParser = queryParser(); IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(queryString("test").field("content", 2.2f).field("name").useDisMax(true)).query(); Query parsedQuery = queryParser.parse(queryStringQuery("test").field("content", 2.2f).field("name").useDisMax(true)).query();
assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class)); assertThat(parsedQuery, instanceOf(DisjunctionMaxQuery.class));
DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) parsedQuery; DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) parsedQuery;
List<Query> disjuncts = disMaxQuery.getDisjuncts(); List<Query> disjuncts = disMaxQuery.getDisjuncts();

View File

@ -126,7 +126,7 @@ public class IndicesLeaksTests extends ElasticsearchIntegrationTest {
private void performCommonOperations() { private void performCommonOperations() {
client().prepareIndex("test", "type", "1").setSource("field1", "value", "field2", 2, "field3", 3.0f).execute().actionGet(); client().prepareIndex("test", "type", "1").setSource("field1", "value", "field2", 2, "field3", 3.0f).execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet(); client().admin().indices().prepareRefresh().execute().actionGet();
client().prepareSearch("test").setQuery(QueryBuilders.queryString("field1:value")).execute().actionGet(); client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("field1:value")).execute().actionGet();
client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field1", "value")).execute().actionGet(); client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field1", "value")).execute().actionGet();
} }
} }

View File

@ -372,7 +372,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1") client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject() .setSource(jsonBuilder().startObject()
.field("source", "productizer") .field("source", "productizer")
.field("query", QueryBuilders.constantScoreQuery(QueryBuilders.queryString("filingcategory:s"))) .field("query", QueryBuilders.constantScoreQuery(QueryBuilders.queryStringQuery("filingcategory:s")))
.endObject()) .endObject())
.setRefresh(true) .setRefresh(true)
.execute().actionGet(); .execute().actionGet();
@ -1654,7 +1654,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", PercolatorService.TYPE_NAME, "1") client().prepareIndex("test", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject() .setSource(jsonBuilder().startObject()
.field("query", QueryBuilders.constantScoreQuery(FilterBuilders.andFilter( .field("query", QueryBuilders.constantScoreQuery(FilterBuilders.andFilter(
FilterBuilders.queryFilter(QueryBuilders.queryString("root")), FilterBuilders.queryFilter(QueryBuilders.queryStringQuery("root")),
FilterBuilders.termFilter("message", "tree")))) FilterBuilders.termFilter("message", "tree"))))
.endObject()) .endObject())
.setRefresh(true) .setRefresh(true)
@ -1729,7 +1729,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
try { try {
client().prepareIndex("idx", PercolatorService.TYPE_NAME, "1") client().prepareIndex("idx", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", QueryBuilders.queryString("color:red")).endObject()) .setSource(jsonBuilder().startObject().field("query", QueryBuilders.queryStringQuery("color:red")).endObject())
.get(); .get();
fail(); fail();
} catch (PercolatorException e) { } catch (PercolatorException e) {
@ -1747,10 +1747,10 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
// The previous percolate request introduced the custom.color field, so now we register the query again // The previous percolate request introduced the custom.color field, so now we register the query again
// and the field name `color` will be resolved to `custom.color` field in mapping via smart field mapping resolving. // and the field name `color` will be resolved to `custom.color` field in mapping via smart field mapping resolving.
client().prepareIndex("idx", PercolatorService.TYPE_NAME, "1") client().prepareIndex("idx", PercolatorService.TYPE_NAME, "1")
.setSource(jsonBuilder().startObject().field("query", QueryBuilders.queryString("color:red")).endObject()) .setSource(jsonBuilder().startObject().field("query", QueryBuilders.queryStringQuery("color:red")).endObject())
.get(); .get();
client().prepareIndex("idx", PercolatorService.TYPE_NAME, "2") client().prepareIndex("idx", PercolatorService.TYPE_NAME, "2")
.setSource(jsonBuilder().startObject().field("query", QueryBuilders.queryString("color:blue")).field("type", "type").endObject()) .setSource(jsonBuilder().startObject().field("query", QueryBuilders.queryStringQuery("color:blue")).field("type", "type").endObject())
.get(); .get();
// The second request will yield a match, since the query during the proper field during parsing. // The second request will yield a match, since the query during the proper field during parsing.

View File

@ -210,7 +210,7 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
assertThat(searchResponse.getHits().getAt(1).id(), anyOf(equalTo("c1"), equalTo("c2"))); assertThat(searchResponse.getHits().getAt(1).id(), anyOf(equalTo("c1"), equalTo("c2")));
assertThat(searchResponse.getHits().getAt(1).field("_parent").value().toString(), equalTo("p1")); assertThat(searchResponse.getHits().getAt(1).field("_parent").value().toString(), equalTo("p1"));
searchResponse = client().prepareSearch("test").setQuery(queryString("_parent:p1")).addFields("_parent").get(); searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("_parent:p1")).addFields("_parent").get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2"))); assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2")));
@ -636,16 +636,16 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH) SearchResponse searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(boolQuery().mustNot(hasChildQuery("child", boolQuery().should(queryString("c_field:*"))))).get(); .setQuery(boolQuery().mustNot(hasChildQuery("child", boolQuery().should(queryStringQuery("c_field:*"))))).get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH) searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(boolQuery().mustNot(hasParentQuery("parent", boolQuery().should(queryString("p_field:*"))))).execute() .setQuery(boolQuery().mustNot(hasParentQuery("parent", boolQuery().should(queryStringQuery("p_field:*"))))).execute()
.actionGet(); .actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH) searchResponse = client().prepareSearch("test").setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(boolQuery().mustNot(topChildrenQuery("child", boolQuery().should(queryString("c_field:*"))))).execute() .setQuery(boolQuery().mustNot(topChildrenQuery("child", boolQuery().should(queryStringQuery("c_field:*"))))).execute()
.actionGet(); .actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
} }
@ -668,7 +668,7 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH) SearchResponse searchResponse = client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(boolQuery().mustNot(topChildrenQuery("child", boolQuery().should(queryString("c_field:*"))))).execute() .setQuery(boolQuery().mustNot(topChildrenQuery("child", boolQuery().should(queryStringQuery("c_field:*"))))).execute()
.actionGet(); .actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
} }
@ -1524,7 +1524,7 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
hasChildQuery( hasChildQuery(
"child_type_one", "child_type_one",
boolQuery().must( boolQuery().must(
queryString("name:William*").analyzeWildcard(true) queryStringQuery("name:William*").analyzeWildcard(true)
) )
) )
) )
@ -1541,7 +1541,7 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
hasChildQuery( hasChildQuery(
"child_type_two", "child_type_two",
boolQuery().must( boolQuery().must(
queryString("name:William*").analyzeWildcard(true) queryStringQuery("name:William*").analyzeWildcard(true)
) )
) )
) )

View File

@ -65,14 +65,14 @@ public class FunctionScoreFieldValueTests extends ElasticsearchIntegrationTest {
// document 2 scores higher because 17 > 5 // document 2 scores higher because 17 > 5
SearchResponse response = client().prepareSearch("test") SearchResponse response = client().prepareSearch("test")
.setExplain(randomBoolean()) .setExplain(randomBoolean())
.setQuery(functionScoreQuery(simpleQueryString("foo"), fieldValueFactorFunction("test"))) .setQuery(functionScoreQuery(simpleQueryStringQuery("foo"), fieldValueFactorFunction("test")))
.get(); .get();
assertOrderedSearchHits(response, "2", "1"); assertOrderedSearchHits(response, "2", "1");
// document 1 scores higher because 1/5 > 1/17 // document 1 scores higher because 1/5 > 1/17
response = client().prepareSearch("test") response = client().prepareSearch("test")
.setExplain(randomBoolean()) .setExplain(randomBoolean())
.setQuery(functionScoreQuery(simpleQueryString("foo"), .setQuery(functionScoreQuery(simpleQueryStringQuery("foo"),
fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL))) fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL)))
.get(); .get();
assertOrderedSearchHits(response, "1", "2"); assertOrderedSearchHits(response, "1", "2");
@ -92,7 +92,7 @@ public class FunctionScoreFieldValueTests extends ElasticsearchIntegrationTest {
try { try {
response = client().prepareSearch("test") response = client().prepareSearch("test")
.setExplain(randomBoolean()) .setExplain(randomBoolean())
.setQuery(functionScoreQuery(simpleQueryString("foo"), .setQuery(functionScoreQuery(simpleQueryStringQuery("foo"),
fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL).factor(0))) fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL).factor(0)))
.get(); .get();
assertFailures(response); assertFailures(response);

View File

@ -817,55 +817,55 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
SearchRequestBuilder req = client().prepareSearch("test").addHighlightedField(fooField); SearchRequestBuilder req = client().prepareSearch("test").addHighlightedField(fooField);
// First check highlighting without any matched fields set // First check highlighting without any matched fields set
SearchResponse resp = req.setQuery(queryString("running scissors").field("foo")).get(); SearchResponse resp = req.setQuery(queryStringQuery("running scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
// And that matching a subfield doesn't automatically highlight it // And that matching a subfield doesn't automatically highlight it
resp = req.setQuery(queryString("foo.plain:running scissors").field("foo")).get(); resp = req.setQuery(queryStringQuery("foo.plain:running scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("running with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("running with <em>scissors</em>"));
// Add the subfield to the list of matched fields but don't match it. Everything should still work // Add the subfield to the list of matched fields but don't match it. Everything should still work
// like before we added it. // like before we added it.
fooField.matchedFields("foo", "foo.plain"); fooField.matchedFields("foo", "foo.plain");
resp = req.setQuery(queryString("running scissors").field("foo")).get(); resp = req.setQuery(queryStringQuery("running scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
// Now make half the matches come from the stored field and half from just a matched field. // Now make half the matches come from the stored field and half from just a matched field.
resp = req.setQuery(queryString("foo.plain:running scissors").field("foo")).get(); resp = req.setQuery(queryStringQuery("foo.plain:running scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
// Now remove the stored field from the matched field list. That should work too. // Now remove the stored field from the matched field list. That should work too.
fooField.matchedFields("foo.plain"); fooField.matchedFields("foo.plain");
resp = req.setQuery(queryString("foo.plain:running scissors").field("foo")).get(); resp = req.setQuery(queryStringQuery("foo.plain:running scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with scissors")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with scissors"));
// Now make sure boosted fields don't blow up when matched fields is both the subfield and stored field. // Now make sure boosted fields don't blow up when matched fields is both the subfield and stored field.
fooField.matchedFields("foo", "foo.plain"); fooField.matchedFields("foo", "foo.plain");
resp = req.setQuery(queryString("foo.plain:running^5 scissors").field("foo")).get(); resp = req.setQuery(queryStringQuery("foo.plain:running^5 scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
// Now just all matches are against the matched field. This still returns highlighting. // Now just all matches are against the matched field. This still returns highlighting.
resp = req.setQuery(queryString("foo.plain:running foo.plain:scissors").field("foo")).get(); resp = req.setQuery(queryStringQuery("foo.plain:running foo.plain:scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
// And all matched field via the queryString's field parameter, just in case // And all matched field via the queryString's field parameter, just in case
resp = req.setQuery(queryString("running scissors").field("foo.plain")).get(); resp = req.setQuery(queryStringQuery("running scissors").field("foo.plain")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
// Finding the same string two ways is ok too // Finding the same string two ways is ok too
resp = req.setQuery(queryString("run foo.plain:running^5 scissors").field("foo")).get(); resp = req.setQuery(queryStringQuery("run foo.plain:running^5 scissors").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
// But we use the best found score when sorting fragments // But we use the best found score when sorting fragments
resp = req.setQuery(queryString("cats foo.plain:cats^5").field("foo")).get(); resp = req.setQuery(queryStringQuery("cats foo.plain:cats^5").field("foo")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk")); assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
// which can also be written by searching on the subfield // which can also be written by searching on the subfield
resp = req.setQuery(queryString("cats").field("foo").field("foo.plain^5")).get(); resp = req.setQuery(queryStringQuery("cats").field("foo").field("foo.plain^5")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk")); assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
// Speaking of two fields, you can have two fields, only one of which has matchedFields enabled // Speaking of two fields, you can have two fields, only one of which has matchedFields enabled
QueryBuilder twoFieldsQuery = queryString("cats").field("foo").field("foo.plain^5") QueryBuilder twoFieldsQuery = queryStringQuery("cats").field("foo").field("foo.plain^5")
.field("bar").field("bar.plain^5"); .field("bar").field("bar.plain^5");
resp = req.setQuery(twoFieldsQuery).addHighlightedField(barField).get(); resp = req.setQuery(twoFieldsQuery).addHighlightedField(barField).get();
assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk")); assertHighlight(resp, 0, "foo", 0, equalTo("junk junk <em>cats</em> junk junk"));
@ -885,27 +885,27 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
// If the stored field doesn't have a value it doesn't matter what you match, you get nothing. // If the stored field doesn't have a value it doesn't matter what you match, you get nothing.
barField.matchedFields("bar", "foo.plain"); barField.matchedFields("bar", "foo.plain");
resp = req.setQuery(queryString("running scissors").field("foo.plain").field("bar")).get(); resp = req.setQuery(queryStringQuery("running scissors").field("foo.plain").field("bar")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("bar"))); assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("bar")));
// If the stored field is found but the matched field isn't then you don't get a result either. // If the stored field is found but the matched field isn't then you don't get a result either.
fooField.matchedFields("bar.plain"); fooField.matchedFields("bar.plain");
resp = req.setQuery(queryString("running scissors").field("foo").field("foo.plain").field("bar").field("bar.plain")).get(); resp = req.setQuery(queryStringQuery("running scissors").field("foo").field("foo.plain").field("bar").field("bar.plain")).get();
assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("foo"))); assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("foo")));
// But if you add the stored field to the list of matched fields then you'll get a result again // But if you add the stored field to the list of matched fields then you'll get a result again
fooField.matchedFields("foo", "bar.plain"); fooField.matchedFields("foo", "bar.plain");
resp = req.setQuery(queryString("running scissors").field("foo").field("foo.plain").field("bar").field("bar.plain")).get(); resp = req.setQuery(queryStringQuery("running scissors").field("foo").field("foo.plain").field("bar").field("bar.plain")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>running</em> with <em>scissors</em>"));
assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("bar"))); assertThat(resp.getHits().getAt(0).getHighlightFields(), not(hasKey("bar")));
// You _can_ highlight fields that aren't subfields of one another. // You _can_ highlight fields that aren't subfields of one another.
resp = req.setQuery(queryString("weird").field("foo").field("foo.plain").field("bar").field("bar.plain")).get(); resp = req.setQuery(queryStringQuery("weird").field("foo").field("foo.plain").field("bar").field("bar.plain")).get();
assertHighlight(resp, 0, "foo", 0, equalTo("<em>weird</em>")); assertHighlight(resp, 0, "foo", 0, equalTo("<em>weird</em>"));
assertHighlight(resp, 0, "bar", 0, equalTo("<em>resul</em>t")); assertHighlight(resp, 0, "bar", 0, equalTo("<em>resul</em>t"));
assertFailures(req.setQuery(queryString("result").field("foo").field("foo.plain").field("bar").field("bar.plain")), assertFailures(req.setQuery(queryStringQuery("result").field("foo").field("foo.plain").field("bar").field("bar.plain")),
RestStatus.INTERNAL_SERVER_ERROR, containsString("String index out of range")); RestStatus.INTERNAL_SERVER_ERROR, containsString("String index out of range"));
} }
@ -1328,7 +1328,7 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
logger.info("--> highlighting and searching on field1"); logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource() SearchSourceBuilder source = searchSource()
.query(commonTerms("field2", "quick brown").cutoffFrequency(100)) .query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
.highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>")); .highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get(); SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get();
@ -1343,7 +1343,7 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog").get(); client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog").get();
refresh(); refresh();
logger.info("--> highlighting and searching on field1"); logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource().query(commonTerms("field2", "quick brown").cutoffFrequency(100)) SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
.highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>")); .highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get(); SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get();
@ -2311,7 +2311,7 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get(); client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
refresh(); refresh();
logger.info("--> highlighting and searching on field1"); logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource().query(commonTerms("field2", "quick brown").cutoffFrequency(100)) SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
.highlight(highlight().field("field2").preTags("<x>").postTags("</x>")); .highlight(highlight().field("field2").preTags("<x>").postTags("</x>"));
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet(); SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
@ -2423,7 +2423,7 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get(); client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
refresh(); refresh();
logger.info("--> highlighting and searching on field2"); logger.info("--> highlighting and searching on field2");
SearchSourceBuilder source = searchSource().query(queryString("qui*").defaultField("field2").rewrite(randomFrom(REWRITE_METHODS))) SearchSourceBuilder source = searchSource().query(queryStringQuery("qui*").defaultField("field2").rewrite(randomFrom(REWRITE_METHODS)))
.highlight(highlight().field("field2")); .highlight(highlight().field("field2"));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get(); SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get();
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!")); assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
@ -2458,7 +2458,7 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
SearchSourceBuilder source = searchSource().query(boolQuery() SearchSourceBuilder source = searchSource().query(boolQuery()
.should(constantScoreQuery(FilterBuilders.missingFilter("field1"))) .should(constantScoreQuery(FilterBuilders.missingFilter("field1")))
.should(matchQuery("field1", "test")) .should(matchQuery("field1", "test"))
.should(filteredQuery(queryString("field1:photo*").rewrite(randomFrom(REWRITE_METHODS)), null))) .should(filteredQuery(queryStringQuery("field1:photo*").rewrite(randomFrom(REWRITE_METHODS)), null)))
.highlight(highlight().field("field1")); .highlight(highlight().field("field1"));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get(); SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get();
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted")); assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
@ -2490,7 +2490,7 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
refresh(); refresh();
logger.info("--> highlighting and searching on field1"); logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource().query(filteredQuery(queryString("field1:photo*").rewrite(randomFrom(REWRITE_METHODS)), missingFilter("field_null"))) SearchSourceBuilder source = searchSource().query(filteredQuery(queryStringQuery("field1:photo*").rewrite(randomFrom(REWRITE_METHODS)), missingFilter("field_null")))
.highlight(highlight().field("field1")); .highlight(highlight().field("field1"));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get(); SearchResponse searchResponse = client().prepareSearch("test").setSource(source.buildAsBytes()).get();
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted")); assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
@ -2639,23 +2639,23 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
// Query string with a single field // Query string with a single field
phraseBoostTestCaseForClauses(highlighterType, 100f, phraseBoostTestCaseForClauses(highlighterType, 100f,
queryString("highlight words together").field("field1"), queryStringQuery("highlight words together").field("field1"),
queryString("\"highlight words together\"").field("field1").autoGeneratePhraseQueries(true)); queryStringQuery("\"highlight words together\"").field("field1").autoGeneratePhraseQueries(true));
// Query string with a single field without dismax // Query string with a single field without dismax
phraseBoostTestCaseForClauses(highlighterType, 100f, phraseBoostTestCaseForClauses(highlighterType, 100f,
queryString("highlight words together").field("field1").useDisMax(false), queryStringQuery("highlight words together").field("field1").useDisMax(false),
queryString("\"highlight words together\"").field("field1").useDisMax(false).autoGeneratePhraseQueries(true)); queryStringQuery("\"highlight words together\"").field("field1").useDisMax(false).autoGeneratePhraseQueries(true));
// Query string with more than one field // Query string with more than one field
phraseBoostTestCaseForClauses(highlighterType, 100f, phraseBoostTestCaseForClauses(highlighterType, 100f,
queryString("highlight words together").field("field1").field("field2"), queryStringQuery("highlight words together").field("field1").field("field2"),
queryString("\"highlight words together\"").field("field1").field("field2").autoGeneratePhraseQueries(true)); queryStringQuery("\"highlight words together\"").field("field1").field("field2").autoGeneratePhraseQueries(true));
// Query string boosting the field // Query string boosting the field
phraseBoostTestCaseForClauses(highlighterType, 1f, phraseBoostTestCaseForClauses(highlighterType, 1f,
queryString("highlight words together").field("field1"), queryStringQuery("highlight words together").field("field1"),
queryString("\"highlight words together\"").field("field1^100").autoGeneratePhraseQueries(true)); queryStringQuery("\"highlight words together\"").field("field1^100").autoGeneratePhraseQueries(true));
} }
private <P extends QueryBuilder & BoostableQueryBuilder<?>> void private <P extends QueryBuilder & BoostableQueryBuilder<?>> void

View File

@ -223,8 +223,8 @@ public class MatchedQueriesTests extends ElasticsearchIntegrationTest {
.setQuery( .setQuery(
boolQuery() boolQuery()
.minimumNumberShouldMatch(1) .minimumNumberShouldMatch(1)
.should(queryString("dolor").queryName("dolor")) .should(queryStringQuery("dolor").queryName("dolor"))
.should(queryString("elit").queryName("elit")) .should(queryStringQuery("elit").queryName("elit"))
) )
.setPreference("_primary") .setPreference("_primary")
.get(); .get();

View File

@ -34,8 +34,8 @@ import java.util.concurrent.ExecutionException;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.queryString; import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.elasticsearch.index.query.QueryBuilders.simpleQueryString; import static org.elasticsearch.index.query.QueryBuilders.simpleQueryStringQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -56,32 +56,32 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "5").setSource("body", "quux baz spaghetti"), client().prepareIndex("test", "type1", "5").setSource("body", "quux baz spaghetti"),
client().prepareIndex("test", "type1", "6").setSource("otherbody", "spaghetti")); client().prepareIndex("test", "type1", "6").setSource("otherbody", "spaghetti"));
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryString("foo bar")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo bar")).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
assertSearchHits(searchResponse, "1", "2", "3"); assertSearchHits(searchResponse, "1", "2", "3");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo bar").defaultOperator(SimpleQueryStringBuilder.Operator.AND)).get(); simpleQueryStringQuery("foo bar").defaultOperator(SimpleQueryStringBuilder.Operator.AND)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("3")); assertFirstHit(searchResponse, hasId("3"));
searchResponse = client().prepareSearch().setQuery(simpleQueryString("\"quux baz\" +(eggplant | spaghetti)")).get(); searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("\"quux baz\" +(eggplant | spaghetti)")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertSearchHits(searchResponse, "4", "5"); assertSearchHits(searchResponse, "4", "5");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("eggplants").analyzer("snowball")).get(); simpleQueryStringQuery("eggplants").analyzer("snowball")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("4")); assertFirstHit(searchResponse, hasId("4"));
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("spaghetti").field("body", 1000.0f).field("otherbody", 2.0f).queryName("myquery")).get(); simpleQueryStringQuery("spaghetti").field("body", 1000.0f).field("otherbody", 2.0f).queryName("myquery")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertFirstHit(searchResponse, hasId("5")); assertFirstHit(searchResponse, hasId("5"));
assertSearchHits(searchResponse, "5", "6"); assertSearchHits(searchResponse, "5", "6");
assertThat(searchResponse.getHits().getAt(0).getMatchedQueries()[0], equalTo("myquery")); assertThat(searchResponse.getHits().getAt(0).getMatchedQueries()[0], equalTo("myquery"));
searchResponse = client().prepareSearch().setQuery(simpleQueryString("spaghetti").field("*body")).get(); searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("spaghetti").field("*body")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertSearchHits(searchResponse, "5", "6"); assertSearchHits(searchResponse, "5", "6");
@ -97,21 +97,21 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("body", "Professional").get(); client().prepareIndex("test", "type1", "1").setSource("body", "Professional").get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryString("Professio*")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("Professio*")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("Professio*").lowercaseExpandedTerms(false)).get(); simpleQueryStringQuery("Professio*").lowercaseExpandedTerms(false)).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("Professionan~1")).get(); simpleQueryStringQuery("Professionan~1")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("Professionan~1").lowercaseExpandedTerms(false)).get(); simpleQueryStringQuery("Professionan~1").lowercaseExpandedTerms(false)).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
} }
@ -121,17 +121,17 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("body", "bılly").get(); client().prepareIndex("test", "type1", "1").setSource("body", "bılly").get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryString("BILL*")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("BILL*")).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
searchResponse = client().prepareSearch().setQuery(queryString("body:BILL*")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("body:BILL*")).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("BILL*").locale(new Locale("tr", "TR"))).get(); simpleQueryStringQuery("BILL*").locale(new Locale("tr", "TR"))).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
queryString("body:BILL*").locale(new Locale("tr", "TR"))).get(); queryStringQuery("body:BILL*").locale(new Locale("tr", "TR"))).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
} }
@ -156,22 +156,22 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery( SearchResponse searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo bar baz").field("body")).get(); simpleQueryStringQuery("foo bar baz").field("body")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo bar baz").field("type1.body")).get(); simpleQueryStringQuery("foo bar baz").field("type1.body")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo bar baz").field("body.sub")).get(); simpleQueryStringQuery("foo bar baz").field("body.sub")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo bar baz").field("type1.body.sub")).get(); simpleQueryStringQuery("foo bar baz").field("type1.body.sub")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
} }
@ -188,7 +188,7 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "6").setSource("otherbody", "spaghetti")); client().prepareIndex("test", "type1", "6").setSource("otherbody", "spaghetti"));
SearchResponse searchResponse = client().prepareSearch().setQuery( SearchResponse searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo bar").flags(SimpleQueryStringFlag.ALL)).get(); simpleQueryStringQuery("foo bar").flags(SimpleQueryStringFlag.ALL)).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
assertSearchHits(searchResponse, "1", "2", "3"); assertSearchHits(searchResponse, "1", "2", "3");
@ -198,21 +198,21 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
assertSearchHits(searchResponse, "1", "2", "3"); assertSearchHits(searchResponse, "1", "2", "3");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo | bar") simpleQueryStringQuery("foo | bar")
.defaultOperator(SimpleQueryStringBuilder.Operator.AND) .defaultOperator(SimpleQueryStringBuilder.Operator.AND)
.flags(SimpleQueryStringFlag.OR)).get(); .flags(SimpleQueryStringFlag.OR)).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
assertSearchHits(searchResponse, "1", "2", "3"); assertSearchHits(searchResponse, "1", "2", "3");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("foo | bar") simpleQueryStringQuery("foo | bar")
.defaultOperator(SimpleQueryStringBuilder.Operator.AND) .defaultOperator(SimpleQueryStringBuilder.Operator.AND)
.flags(SimpleQueryStringFlag.NONE)).get(); .flags(SimpleQueryStringFlag.NONE)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("3")); assertFirstHit(searchResponse, hasId("3"));
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("baz | egg*") simpleQueryStringQuery("baz | egg*")
.defaultOperator(SimpleQueryStringBuilder.Operator.AND) .defaultOperator(SimpleQueryStringBuilder.Operator.AND)
.flags(SimpleQueryStringFlag.NONE)).get(); .flags(SimpleQueryStringFlag.NONE)).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
@ -229,7 +229,7 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setQuery(
simpleQueryString("baz | egg*") simpleQueryStringQuery("baz | egg*")
.defaultOperator(SimpleQueryStringBuilder.Operator.AND) .defaultOperator(SimpleQueryStringBuilder.Operator.AND)
.flags(SimpleQueryStringFlag.WHITESPACE, SimpleQueryStringFlag.PREFIX)).get(); .flags(SimpleQueryStringFlag.WHITESPACE, SimpleQueryStringFlag.PREFIX)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
@ -243,12 +243,12 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test2", "type1", "10").setSource("field", 5)); client().prepareIndex("test2", "type1", "10").setSource("field", 5));
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryString("foo").field("field")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo").field("field")).get();
assertFailures(searchResponse); assertFailures(searchResponse);
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery(simpleQueryString("foo").field("field").lenient(true)).get(); searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo").field("field").lenient(true)).get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
@ -260,7 +260,7 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "doc", "1").setSource("num", 1, "body", "foo bar baz"), client().prepareIndex("test", "doc", "1").setSource("num", 1, "body", "foo bar baz"),
client().prepareIndex("test", "doc", "2").setSource("num", 2, "body", "eggplant spaghetti lasagna")); client().prepareIndex("test", "doc", "2").setSource("num", 2, "body", "eggplant spaghetti lasagna"));
BoolQueryBuilder q = boolQuery().should(simpleQueryString("bar").field("num").field("body").lenient(true)); BoolQueryBuilder q = boolQuery().should(simpleQueryStringQuery("bar").field("num").field("body").lenient(true));
SearchResponse resp = client().prepareSearch("test").setQuery(q).get(); SearchResponse resp = client().prepareSearch("test").setQuery(q).get();
assertNoFailures(resp); assertNoFailures(resp);
// the bug is that this would be parsed into basically a match_all // the bug is that this would be parsed into basically a match_all
@ -288,7 +288,7 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
indexRandom(true, client().prepareIndex("test1", "type1", "1").setSource("location", "Köln")); indexRandom(true, client().prepareIndex("test1", "type1", "1").setSource("location", "Köln"));
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryString("Köln*").analyzeWildcard(true).field("location")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("Köln*").analyzeWildcard(true).field("location")).get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");

View File

@ -100,8 +100,8 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox jumps"), indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox jumps"),
client().prepareIndex("test", "type1", "2").setSource("field1", "quick brown"), client().prepareIndex("test", "type1", "2").setSource("field1", "quick brown"),
client().prepareIndex("test", "type1", "3").setSource("field1", "quick")); client().prepareIndex("test", "type1", "3").setSource("field1", "quick"));
assertHitCount(client().prepareSearch().setQuery(queryString("quick")).get(), 3l); assertHitCount(client().prepareSearch().setQuery(queryStringQuery("quick")).get(), 3l);
assertHitCount(client().prepareSearch().setQuery(queryString("")).get(), 0l); // return no docs assertHitCount(client().prepareSearch().setQuery(queryStringQuery("")).get(), 0l); // return no docs
} }
@Test // see https://github.com/elasticsearch/elasticsearch/issues/3177 @Test // see https://github.com/elasticsearch/elasticsearch/issues/3177
@ -240,7 +240,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
); );
int iters = scaledRandomIntBetween(100, 200); int iters = scaledRandomIntBetween(100, 200);
for (int i = 0; i < iters; i++) { for (int i = 0; i < iters; i++) {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(queryString("*:*^10.0").boost(10.0f)).get(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("*:*^10.0").boost(10.0f)).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
searchResponse = client().prepareSearch("test").setQuery( searchResponse = client().prepareSearch("test").setQuery(
@ -259,7 +259,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("message", "test message", "comment", "whatever"), indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("message", "test message", "comment", "whatever"),
client().prepareIndex("test", "type1", "2").setSource("message", "hello world", "comment", "test comment")); client().prepareIndex("test", "type1", "2").setSource("message", "hello world", "comment", "test comment"));
SearchResponse searchResponse = client().prepareSearch().setQuery(commonTerms("_all", "test")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(commonTermsQuery("_all", "test")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
assertSecondHit(searchResponse, hasId("1")); assertSecondHit(searchResponse, hasId("1"));
@ -275,35 +275,35 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"), client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"),
client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") ); client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") );
SearchResponse searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
assertThirdHit(searchResponse, hasId("3")); assertThirdHit(searchResponse, hasId("3"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get();
assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
// Default // Default
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the quick brown").cutoffFrequency(3)).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3)).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
assertThirdHit(searchResponse, hasId("3")); assertThirdHit(searchResponse, hasId("3"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the huge fox").lowFreqMinimumShouldMatch("2")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the huge fox").lowFreqMinimumShouldMatch("2")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("3")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("3")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("4")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("4")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
@ -312,11 +312,11 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
// Default // Default
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the lazy fox brown").cutoffFrequency(1)).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the quick brown").cutoffFrequency(3).analyzer("stop")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).analyzer("stop")).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
// stop drops "the" since its a stopword // stop drops "the" since its a stopword
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
@ -368,35 +368,35 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"), client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"),
client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") ); client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") );
SearchResponse searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
assertThirdHit(searchResponse, hasId("3")); assertThirdHit(searchResponse, hasId("3"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get();
assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
// Default // Default
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast brown").cutoffFrequency(3)).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast brown").cutoffFrequency(3)).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
assertThirdHit(searchResponse, hasId("3")); assertThirdHit(searchResponse, hasId("3"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast huge fox").lowFreqMinimumShouldMatch("3")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast huge fox").lowFreqMinimumShouldMatch("3")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("5")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("5")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("6")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("6")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
@ -405,11 +405,11 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
// Default // Default
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast lazy fox brown").cutoffFrequency(1)).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast lazy fox brown").cutoffFrequency(1)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the quick brown").cutoffFrequency(3).analyzer("stop")).get(); searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3).analyzer("stop")).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
// stop drops "the" since its a stopword // stop drops "the" since its a stopword
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
@ -488,19 +488,19 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get(); client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryString("value*").analyzeWildcard(true)).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("value*").analyzeWildcard(true)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("*ue*").analyzeWildcard(true)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("*ue*").analyzeWildcard(true)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("*ue_1").analyzeWildcard(true)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("*ue_1").analyzeWildcard(true)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("val*e_1").analyzeWildcard(true)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("val*e_1").analyzeWildcard(true)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("v?l*e?1").analyzeWildcard(true)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("v?l*e?1").analyzeWildcard(true)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
} }
@ -511,17 +511,17 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get(); client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryString("VALUE_3~1").lowercaseExpandedTerms(true)).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("VALUE_3~1").lowercaseExpandedTerms(true)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("VALUE_3~1").lowercaseExpandedTerms(false)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("VALUE_3~1").lowercaseExpandedTerms(false)).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
searchResponse = client().prepareSearch().setQuery(queryString("ValUE_*").lowercaseExpandedTerms(true)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("ValUE_*").lowercaseExpandedTerms(true)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("vAl*E_1")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("vAl*E_1")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("[VALUE_1 TO VALUE_3]")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("[VALUE_1 TO VALUE_3]")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("[VALUE_1 TO VALUE_3]").lowercaseExpandedTerms(false)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("[VALUE_1 TO VALUE_3]").lowercaseExpandedTerms(false)).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
} }
@ -539,14 +539,14 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get(); client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryString("past:[now-2M/d TO now/d]")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("future:[now/d TO now+2M/d]").lowercaseExpandedTerms(false)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("future:[now/d TO now+2M/d]").lowercaseExpandedTerms(false)).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
try { try {
client().prepareSearch().setQuery(queryString("future:[now/D TO now+2M/d]").lowercaseExpandedTerms(false)).get(); client().prepareSearch().setQuery(queryStringQuery("future:[now/D TO now+2M/d]").lowercaseExpandedTerms(false)).get();
fail("expected SearchPhaseExecutionException (total failure)"); fail("expected SearchPhaseExecutionException (total failure)");
} catch (SearchPhaseExecutionException e) { } catch (SearchPhaseExecutionException e) {
assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST)); assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST));
@ -569,7 +569,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type", "1").setSource("past", now).get(); client().prepareIndex("test", "type", "1").setSource("past", now).get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryString("past:[now-1m/m TO now+1m/m]") SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-1m/m TO now+1m/m]")
.timeZone(timeZone.getID())).get(); .timeZone(timeZone.getID())).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
} }
@ -684,7 +684,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertSearchHits(searchResponse, "1", "2"); assertSearchHits(searchResponse, "1", "2");
searchResponse = client().prepareSearch().setQuery(queryString("_exists_:field1")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("_exists_:field1")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertSearchHits(searchResponse, "1", "2"); assertSearchHits(searchResponse, "1", "2");
@ -718,7 +718,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertSearchHits(searchResponse, "3", "4"); assertSearchHits(searchResponse, "3", "4");
searchResponse = client().prepareSearch().setQuery(queryString("_missing_:field1")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("_missing_:field1")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertSearchHits(searchResponse, "3", "4"); assertSearchHits(searchResponse, "3", "4");
@ -959,16 +959,16 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get(); client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryString("str:kimcy~1")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("str:kimcy~1")).get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
searchResponse = client().prepareSearch().setQuery(queryString("num:11~1")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:11~1")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
searchResponse = client().prepareSearch().setQuery(queryString("date:2012-02-02~1d")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("date:2012-02-02~1d")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
} }
@ -982,14 +982,14 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
); );
SearchResponse searchResponse = client().prepareSearch() SearchResponse searchResponse = client().prepareSearch()
.setQuery(queryString("\"phrase match\"").field("important", boost).field("less_important")).get(); .setQuery(queryStringQuery("\"phrase match\"").field("important", boost).field("less_important")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1)); assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1));
searchResponse = client().prepareSearch() searchResponse = client().prepareSearch()
.setQuery(queryString("\"phrase match\"").field("important", boost).field("less_important").useDisMax(false)).get(); .setQuery(queryStringQuery("\"phrase match\"").field("important", boost).field("less_important").useDisMax(false)).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
assertFirstHit(searchResponse, hasId("1")); assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
@ -1003,27 +1003,27 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get(); client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryString("num:>19")).get(); SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>19")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(queryString("num:>20")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>20")).get();
assertHitCount(searchResponse, 0l); assertHitCount(searchResponse, 0l);
searchResponse = client().prepareSearch().setQuery(queryString("num:>=20")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>=20")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(queryString("num:>11")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>11")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
searchResponse = client().prepareSearch().setQuery(queryString("num:<20")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:<20")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(queryString("num:<=20")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:<=20")).get();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
searchResponse = client().prepareSearch().setQuery(queryString("+num:>11 +num:<20")).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("+num:>11 +num:<20")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
} }
@ -1625,20 +1625,20 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
public void testMultiFieldQueryString() { public void testMultiFieldQueryString() {
client().prepareIndex("test", "s", "1").setSource("field1", "value1", "field2", "value2").setRefresh(true).get(); client().prepareIndex("test", "s", "1").setSource("field1", "value1", "field2", "value2").setRefresh(true).get();
logger.info("regular"); logger.info("regular");
assertHitCount(client().prepareSearch("test").setQuery(queryString("value1").field("field1").field("field2")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("value1").field("field1").field("field2")).get(), 1);
assertHitCount(client().prepareSearch("test").setQuery(queryString("field\\*:value1")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("field\\*:value1")).get(), 1);
logger.info("prefix"); logger.info("prefix");
assertHitCount(client().prepareSearch("test").setQuery(queryString("value*").field("field1").field("field2")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("value*").field("field1").field("field2")).get(), 1);
assertHitCount(client().prepareSearch("test").setQuery(queryString("field\\*:value*")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("field\\*:value*")).get(), 1);
logger.info("wildcard"); logger.info("wildcard");
assertHitCount(client().prepareSearch("test").setQuery(queryString("v?lue*").field("field1").field("field2")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("v?lue*").field("field1").field("field2")).get(), 1);
assertHitCount(client().prepareSearch("test").setQuery(queryString("field\\*:v?lue*")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("field\\*:v?lue*")).get(), 1);
logger.info("fuzzy"); logger.info("fuzzy");
assertHitCount(client().prepareSearch("test").setQuery(queryString("value~").field("field1").field("field2")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("value~").field("field1").field("field2")).get(), 1);
assertHitCount(client().prepareSearch("test").setQuery(queryString("field\\*:value~")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("field\\*:value~")).get(), 1);
logger.info("regexp"); logger.info("regexp");
assertHitCount(client().prepareSearch("test").setQuery(queryString("/value[01]/").field("field1").field("field2")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("/value[01]/").field("field1").field("field2")).get(), 1);
assertHitCount(client().prepareSearch("test").setQuery(queryString("field\\*:/value[01]/")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryStringQuery("field\\*:/value[01]/")).get(), 1);
} }
// see #3881 - for extensive description of the issue // see #3881 - for extensive description of the issue
@ -1716,19 +1716,19 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "test", "1").setSource("text", "quick brown fox").get(); client().prepareIndex("test", "test", "1").setSource("text", "quick brown fox").get();
refresh(); refresh();
SearchResponse searchResponse = client().prepareSearch("test").setQuery(queryString("quick").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
searchResponse = client().prepareSearch("test").setQuery(queryString("quick brown").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get(); searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick brown").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
searchResponse = client().prepareSearch().setQuery(queryString("fast").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get(); searchResponse = client().prepareSearch().setQuery(queryStringQuery("fast").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
client().prepareIndex("test", "test", "2").setSource("text", "fast brown fox").get(); client().prepareIndex("test", "test", "2").setSource("text", "fast brown fox").get();
refresh(); refresh();
searchResponse = client().prepareSearch("test").setQuery(queryString("quick").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get(); searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get();
assertHitCount(searchResponse, 2); assertHitCount(searchResponse, 2);
searchResponse = client().prepareSearch("test").setQuery(queryString("quick brown").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get(); searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick brown").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get();
assertHitCount(searchResponse, 2); assertHitCount(searchResponse, 2);
} }
@ -1755,7 +1755,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
SearchResponse response = client() SearchResponse response = client()
.prepareSearch("test") .prepareSearch("test")
.setQuery( .setQuery(
queryString("foo.baz").useDisMax(false).defaultOperator(QueryStringQueryBuilder.Operator.AND) queryStringQuery("foo.baz").useDisMax(false).defaultOperator(QueryStringQueryBuilder.Operator.AND)
.field("field1").field("field2")).get(); .field("field1").field("field2")).get();
assertHitCount(response, 1l); assertHitCount(response, 1l);
} }
@ -2081,23 +2081,23 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
client().prepareIndex("test", "product", "2").setSource("desc", "one two three").get(); client().prepareIndex("test", "product", "2").setSource("desc", "one two three").get();
refresh(); refresh();
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("\"one two\"").defaultField("desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
assertHitCount(searchResponse, 2); assertHitCount(searchResponse, 2);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("\"one two\"").field("product.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").field("product.desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("\"one three\"~5").field("product.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one three\"~5").field("product.desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("\"one two\"").defaultField("customer.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("customer.desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("\"one two\"").defaultField("customer.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("customer.desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
} }
@ -2528,7 +2528,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
SearchResponse response = client().prepareSearch("test") SearchResponse response = client().prepareSearch("test")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.queryString("xyz").boost(100)) .setQuery(QueryBuilders.queryStringQuery("xyz").boost(100))
.get(); .get();
assertThat(response.getHits().totalHits(), equalTo(1l)); assertThat(response.getHits().totalHits(), equalTo(1l));
assertThat(response.getHits().getAt(0).id(), equalTo("1")); assertThat(response.getHits().getAt(0).id(), equalTo("1"));
@ -2537,7 +2537,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
response = client().prepareSearch("test") response = client().prepareSearch("test")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.queryString("xyz").boost(100)) .setQuery(QueryBuilders.queryStringQuery("xyz").boost(100))
.get(); .get();
assertThat(response.getHits().totalHits(), equalTo(1l)); assertThat(response.getHits().totalHits(), equalTo(1l));

View File

@ -38,7 +38,6 @@ import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.rescore.RescoreBuilder.QueryRescorer; import org.elasticsearch.search.rescore.RescoreBuilder.QueryRescorer;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test; import org.junit.Test;
@ -675,10 +674,10 @@ public class QueryRescorerTests extends ElasticsearchIntegrationTest {
// Now use one rescore to drag the number we're looking for into the window of another // Now use one rescore to drag the number we're looking for into the window of another
QueryRescorer ninetyIsGood = RescoreBuilder.queryRescorer( QueryRescorer ninetyIsGood = RescoreBuilder.queryRescorer(
QueryBuilders.functionScoreQuery(QueryBuilders.queryString("*ninety*")).boostMode(CombineFunction.REPLACE) QueryBuilders.functionScoreQuery(QueryBuilders.queryStringQuery("*ninety*")).boostMode(CombineFunction.REPLACE)
.add(ScoreFunctionBuilders.scriptFunction("1000.0f"))).setScoreMode("total"); .add(ScoreFunctionBuilders.scriptFunction("1000.0f"))).setScoreMode("total");
QueryRescorer oneToo = RescoreBuilder.queryRescorer( QueryRescorer oneToo = RescoreBuilder.queryRescorer(
QueryBuilders.functionScoreQuery(QueryBuilders.queryString("*one*")).boostMode(CombineFunction.REPLACE) QueryBuilders.functionScoreQuery(QueryBuilders.queryStringQuery("*one*")).boostMode(CombineFunction.REPLACE)
.add(ScoreFunctionBuilders.scriptFunction("1000.0f"))).setScoreMode("total"); .add(ScoreFunctionBuilders.scriptFunction("1000.0f"))).setScoreMode("total");
request.clearRescorers().addRescorer(ninetyIsGood).addRescorer(oneToo, 10); request.clearRescorers().addRescorer(ninetyIsGood).addRescorer(oneToo, 10);
response = request.setSize(2).get(); response = request.setSize(2).get();

View File

@ -193,7 +193,7 @@ public class SearchScrollTests extends ElasticsearchIntegrationTest {
assertThat(client().prepareCount().setQuery(termQuery("message", "update")).execute().actionGet().getCount(), equalTo(0l)); assertThat(client().prepareCount().setQuery(termQuery("message", "update")).execute().actionGet().getCount(), equalTo(0l));
SearchResponse searchResponse = client().prepareSearch() SearchResponse searchResponse = client().prepareSearch()
.setQuery(queryString("user:kimchy")) .setQuery(queryStringQuery("user:kimchy"))
.setSize(35) .setSize(35)
.setScroll(TimeValue.timeValueMinutes(2)) .setScroll(TimeValue.timeValueMinutes(2))
.addSort("postDate", SortOrder.ASC) .addSort("postDate", SortOrder.ASC)

View File

@ -114,14 +114,14 @@ public class SimpleSearchTests extends ElasticsearchIntegrationTest {
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(QueryBuilders.queryString("_id:XXX1")).execute().actionGet(); searchResponse = client().prepareSearch().setQuery(QueryBuilders.queryStringQuery("_id:XXX1")).execute().actionGet();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
// id is not index, but we can automatically support prefix as well // id is not index, but we can automatically support prefix as well
searchResponse = client().prepareSearch().setQuery(QueryBuilders.prefixQuery("_id", "XXX")).execute().actionGet(); searchResponse = client().prepareSearch().setQuery(QueryBuilders.prefixQuery("_id", "XXX")).execute().actionGet();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch().setQuery(QueryBuilders.queryString("_id:XXX*").lowercaseExpandedTerms(false)).execute().actionGet(); searchResponse = client().prepareSearch().setQuery(QueryBuilders.queryStringQuery("_id:XXX*").lowercaseExpandedTerms(false)).execute().actionGet();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
} }
@ -167,7 +167,7 @@ public class SimpleSearchTests extends ElasticsearchIntegrationTest {
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet(); searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet();
assertHitCount(searchResponse, 2l); assertHitCount(searchResponse, 2l);
} }

View File

@ -41,7 +41,7 @@ import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.QueryBuilders.queryString; import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
@ -66,15 +66,15 @@ public class SimpleValidateQueryTests extends ElasticsearchIntegrationTest {
refresh(); refresh();
assertThat(client().admin().indices().prepareValidateQuery("test").setSource("foo".getBytes(Charsets.UTF_8)).execute().actionGet().isValid(), equalTo(false)); assertThat(client().admin().indices().prepareValidateQuery("test").setSource("foo".getBytes(Charsets.UTF_8)).execute().actionGet().isValid(), equalTo(false));
assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("_id:1")).execute().actionGet().isValid(), equalTo(true)); assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryStringQuery("_id:1")).execute().actionGet().isValid(), equalTo(true));
assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("_i:d:1")).execute().actionGet().isValid(), equalTo(false)); assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryStringQuery("_i:d:1")).execute().actionGet().isValid(), equalTo(false));
assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("foo:1")).execute().actionGet().isValid(), equalTo(true)); assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryStringQuery("foo:1")).execute().actionGet().isValid(), equalTo(true));
assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("bar:hey")).execute().actionGet().isValid(), equalTo(false)); assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryStringQuery("bar:hey")).execute().actionGet().isValid(), equalTo(false));
assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("nonexistent:hello")).execute().actionGet().isValid(), equalTo(true)); assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryStringQuery("nonexistent:hello")).execute().actionGet().isValid(), equalTo(true));
assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("foo:1 AND")).execute().actionGet().isValid(), equalTo(false)); assertThat(client().admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryStringQuery("foo:1 AND")).execute().actionGet().isValid(), equalTo(false));
} }
private static String filter(String uncachedFilter) { private static String filter(String uncachedFilter) {
@ -119,12 +119,12 @@ public class SimpleValidateQueryTests extends ElasticsearchIntegrationTest {
assertThat(response.getQueryExplanation().get(0).getExplanation(), nullValue()); assertThat(response.getQueryExplanation().get(0).getExplanation(), nullValue());
final String typeFilter = filter("_type:type1"); final String typeFilter = filter("_type:type1");
assertExplanation(QueryBuilders.queryString("_id:1"), equalTo("filtered(ConstantScore(_uid:type1#1))->" + typeFilter)); assertExplanation(QueryBuilders.queryStringQuery("_id:1"), equalTo("filtered(ConstantScore(_uid:type1#1))->" + typeFilter));
assertExplanation(QueryBuilders.idsQuery("type1").addIds("1").addIds("2"), assertExplanation(QueryBuilders.idsQuery("type1").addIds("1").addIds("2"),
equalTo("filtered(ConstantScore(_uid:type1#1 _uid:type1#2))->" + typeFilter)); equalTo("filtered(ConstantScore(_uid:type1#1 _uid:type1#2))->" + typeFilter));
assertExplanation(QueryBuilders.queryString("foo"), equalTo("filtered(_all:foo)->" + typeFilter)); assertExplanation(QueryBuilders.queryStringQuery("foo"), equalTo("filtered(_all:foo)->" + typeFilter));
assertExplanation(QueryBuilders.filteredQuery( assertExplanation(QueryBuilders.filteredQuery(
QueryBuilders.termQuery("foo", "1"), QueryBuilders.termQuery("foo", "1"),
@ -229,7 +229,7 @@ public class SimpleValidateQueryTests extends ElasticsearchIntegrationTest {
for (Client client : internalCluster()) { for (Client client : internalCluster()) {
ValidateQueryResponse response = client.admin().indices().prepareValidateQuery("test") ValidateQueryResponse response = client.admin().indices().prepareValidateQuery("test")
.setQuery(QueryBuilders.queryString("foo")) .setQuery(QueryBuilders.queryStringQuery("foo"))
.setExplain(true) .setExplain(true)
.execute().actionGet(); .execute().actionGet();
assertThat(response.isValid(), equalTo(true)); assertThat(response.isValid(), equalTo(true));
@ -253,7 +253,7 @@ public class SimpleValidateQueryTests extends ElasticsearchIntegrationTest {
refresh(); refresh();
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery() ValidateQueryResponse response = client().admin().indices().prepareValidateQuery()
.setQuery(queryString("past:[now-2M/d TO now/d]")).setExplain(true).get(); .setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).setExplain(true).get();
assertNoFailures(response); assertNoFailures(response);
assertThat(response.getQueryExplanation().size(), equalTo(1)); assertThat(response.getQueryExplanation().size(), equalTo(1));