Rename field name constants in AbstractBuilderTestCase (#53234)

Some field name constants were not updaten when we moved from "string" to "text"
and "keyword" fields. Renaming them makes it easier and faster to know which
field type is used in test subclassing this base test case.
This commit is contained in:
Christoph Büscher 2020-04-03 17:28:22 +02:00 committed by GitHub
parent 470aa9a5f1
commit 8c9ac14a98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 546 additions and 545 deletions

View File

@ -108,7 +108,7 @@ public class RankFeatureQueryBuilderTests extends AbstractQueryTestCase<RankFeat
public void testIllegalField() throws IOException {
String query = "{\n" +
" \"rank_feature\" : {\n" +
" \"field\": \"" + STRING_FIELD_NAME + "\"\n" +
" \"field\": \"" + TEXT_FIELD_NAME + "\"\n" +
" }\n" +
"}";
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parseQuery(query).toQuery(createShardContext()));

View File

@ -106,10 +106,10 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
.field(PARENT_DOC, CHILD_DOC)
.endObject()
.endObject()
.startObject(STRING_FIELD_NAME)
.startObject(TEXT_FIELD_NAME)
.field("type", "text")
.endObject()
.startObject(STRING_FIELD_NAME_2)
.startObject(KEYWORD_FIELD_NAME)
.field("type", "keyword")
.endObject()
.startObject(INT_FIELD_NAME)
@ -159,7 +159,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
hqb.innerHit(new InnerHitBuilder()
.setName(randomAlphaOfLengthBetween(1, 10))
.setSize(randomIntBetween(0, 100))
.addSort(new FieldSortBuilder(STRING_FIELD_NAME_2).order(SortOrder.ASC)));
.addSort(new FieldSortBuilder(KEYWORD_FIELD_NAME).order(SortOrder.ASC)));
}
return hqb;
}

View File

@ -90,10 +90,10 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
.field(PARENT_DOC, CHILD_DOC)
.endObject()
.endObject()
.startObject(STRING_FIELD_NAME)
.startObject(TEXT_FIELD_NAME)
.field("type", "text")
.endObject()
.startObject(STRING_FIELD_NAME_2)
.startObject(KEYWORD_FIELD_NAME)
.field("type", "keyword")
.endObject()
.startObject(INT_FIELD_NAME)
@ -133,7 +133,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
hqb.innerHit(new InnerHitBuilder()
.setName(randomAlphaOfLengthBetween(1, 10))
.setSize(randomIntBetween(0, 100))
.addSort(new FieldSortBuilder(STRING_FIELD_NAME_2).order(SortOrder.ASC)));
.addSort(new FieldSortBuilder(KEYWORD_FIELD_NAME).order(SortOrder.ASC)));
}
return hqb;
}

View File

@ -81,10 +81,10 @@ public class ParentIdQueryBuilderTests extends AbstractQueryTestCase<ParentIdQue
.field("parent", "child")
.endObject()
.endObject()
.startObject(STRING_FIELD_NAME)
.startObject(TEXT_FIELD_NAME)
.field("type", "text")
.endObject()
.startObject(STRING_FIELD_NAME_2)
.startObject(KEYWORD_FIELD_NAME)
.field("type", "keyword")
.endObject()
.startObject(INT_FIELD_NAME)

View File

@ -97,7 +97,7 @@ public class PercolateQueryBuilderTests extends AbstractQueryTestCase<PercolateQ
queryField, "type=percolator", aliasField, "type=alias,path=" + queryField
))), MapperService.MergeReason.MAPPING_UPDATE);
mapperService.merge(docType, new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(docType,
STRING_FIELD_NAME, "type=text"
TEXT_FIELD_NAME, "type=text"
))), MapperService.MergeReason.MAPPING_UPDATE);
}

View File

@ -197,15 +197,15 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
public void testMinShouldMatchBiggerThanNumberOfShouldClauses() throws Exception {
BooleanQuery bq = (BooleanQuery) parseQuery(
boolQuery()
.should(termQuery(STRING_FIELD_NAME, "bar"))
.should(termQuery(STRING_FIELD_NAME_2, "bar2"))
.should(termQuery(TEXT_FIELD_NAME, "bar"))
.should(termQuery(KEYWORD_FIELD_NAME, "bar2"))
.minimumShouldMatch("3")).toQuery(createShardContext());
assertEquals(3, bq.getMinimumNumberShouldMatch());
bq = (BooleanQuery) parseQuery(
boolQuery()
.should(termQuery(STRING_FIELD_NAME, "bar"))
.should(termQuery(STRING_FIELD_NAME_2, "bar2"))
.should(termQuery(TEXT_FIELD_NAME, "bar"))
.should(termQuery(KEYWORD_FIELD_NAME, "bar2"))
.minimumShouldMatch(3)).toQuery(createShardContext());
assertEquals(3, bq.getMinimumNumberShouldMatch());
}
@ -213,8 +213,8 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
public void testMinShouldMatchDisableCoord() throws Exception {
BooleanQuery bq = (BooleanQuery) parseQuery(
boolQuery()
.should(termQuery(STRING_FIELD_NAME, "bar"))
.should(termQuery(STRING_FIELD_NAME, "bar2"))
.should(termQuery(TEXT_FIELD_NAME, "bar"))
.should(termQuery(TEXT_FIELD_NAME, "bar2"))
.minimumShouldMatch("3")).toQuery(createShardContext());
assertEquals(3, bq.getMinimumNumberShouldMatch());
}
@ -311,22 +311,22 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
boolean mustRewrite = false;
if (randomBoolean()) {
mustRewrite = true;
boolQueryBuilder.must(new WrapperQueryBuilder(new TermsQueryBuilder(STRING_FIELD_NAME, "must").toString()));
boolQueryBuilder.must(new WrapperQueryBuilder(new TermsQueryBuilder(TEXT_FIELD_NAME, "must").toString()));
}
if (randomBoolean()) {
mustRewrite = true;
boolQueryBuilder.should(new WrapperQueryBuilder(new TermsQueryBuilder(STRING_FIELD_NAME, "should").toString()));
boolQueryBuilder.should(new WrapperQueryBuilder(new TermsQueryBuilder(TEXT_FIELD_NAME, "should").toString()));
}
if (randomBoolean()) {
mustRewrite = true;
boolQueryBuilder.filter(new WrapperQueryBuilder(new TermsQueryBuilder(STRING_FIELD_NAME, "filter").toString()));
boolQueryBuilder.filter(new WrapperQueryBuilder(new TermsQueryBuilder(TEXT_FIELD_NAME, "filter").toString()));
}
if (randomBoolean()) {
mustRewrite = true;
boolQueryBuilder.mustNot(new WrapperQueryBuilder(new TermsQueryBuilder(STRING_FIELD_NAME, "must_not").toString()));
boolQueryBuilder.mustNot(new WrapperQueryBuilder(new TermsQueryBuilder(TEXT_FIELD_NAME, "must_not").toString()));
}
if (mustRewrite == false && randomBoolean()) {
boolQueryBuilder.must(new TermsQueryBuilder(STRING_FIELD_NAME, "no_rewrite"));
boolQueryBuilder.must(new TermsQueryBuilder(TEXT_FIELD_NAME, "no_rewrite"));
}
QueryBuilder rewritten = boolQueryBuilder.rewrite(createShardContext());
if (mustRewrite == false && boolQueryBuilder.must().isEmpty()) {
@ -337,16 +337,16 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
if (mustRewrite) {
assertNotSame(rewrite, boolQueryBuilder);
if (boolQueryBuilder.must().isEmpty() == false) {
assertEquals(new TermsQueryBuilder(STRING_FIELD_NAME, "must"), rewrite.must().get(0));
assertEquals(new TermsQueryBuilder(TEXT_FIELD_NAME, "must"), rewrite.must().get(0));
}
if (boolQueryBuilder.should().isEmpty() == false) {
assertEquals(new TermsQueryBuilder(STRING_FIELD_NAME, "should"), rewrite.should().get(0));
assertEquals(new TermsQueryBuilder(TEXT_FIELD_NAME, "should"), rewrite.should().get(0));
}
if (boolQueryBuilder.mustNot().isEmpty() == false) {
assertEquals(new TermsQueryBuilder(STRING_FIELD_NAME, "must_not"), rewrite.mustNot().get(0));
assertEquals(new TermsQueryBuilder(TEXT_FIELD_NAME, "must_not"), rewrite.mustNot().get(0));
}
if (boolQueryBuilder.filter().isEmpty() == false) {
assertEquals(new TermsQueryBuilder(STRING_FIELD_NAME, "filter"), rewrite.filter().get(0));
assertEquals(new TermsQueryBuilder(TEXT_FIELD_NAME, "filter"), rewrite.filter().get(0));
}
} else {
assertSame(rewrite, boolQueryBuilder);
@ -379,14 +379,14 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
assertEquals(new MatchNoneQueryBuilder(), rewritten);
boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(new TermQueryBuilder(STRING_FIELD_NAME,"bar"));
boolQueryBuilder.must(new TermQueryBuilder(TEXT_FIELD_NAME,"bar"));
boolQueryBuilder.filter(new WrapperQueryBuilder(new WrapperQueryBuilder(new MatchNoneQueryBuilder().toString()).toString()));
rewritten = boolQueryBuilder.rewrite(createShardContext());
assertEquals(new MatchNoneQueryBuilder(), rewritten);
boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(new TermQueryBuilder(STRING_FIELD_NAME,"bar"));
boolQueryBuilder.filter(new BoolQueryBuilder().should(new TermQueryBuilder(STRING_FIELD_NAME,"bar"))
boolQueryBuilder.must(new TermQueryBuilder(TEXT_FIELD_NAME,"bar"));
boolQueryBuilder.filter(new BoolQueryBuilder().should(new TermQueryBuilder(TEXT_FIELD_NAME,"bar"))
.filter(new MatchNoneQueryBuilder()));
rewritten = Rewriteable.rewrite(boolQueryBuilder, createShardContext());
assertEquals(new MatchNoneQueryBuilder(), rewritten);
@ -397,7 +397,7 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
assertEquals(new MatchNoneQueryBuilder(), rewritten);
boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.should(new TermQueryBuilder(STRING_FIELD_NAME, "bar"));
boolQueryBuilder.should(new TermQueryBuilder(TEXT_FIELD_NAME, "bar"));
boolQueryBuilder.should(new WrapperQueryBuilder(new MatchNoneQueryBuilder().toString()));
rewritten = Rewriteable.rewrite(boolQueryBuilder, createShardContext());
assertNotEquals(new MatchNoneQueryBuilder(), rewritten);

View File

@ -46,8 +46,8 @@ public class CommonTermsQueryBuilderTests extends AbstractQueryTestCase<CommonTe
text.append(randomAlphaOfLengthBetween(1, 10)).append(" ");
}
String fieldName = randomFrom(STRING_FIELD_NAME,
STRING_ALIAS_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME,
TEXT_ALIAS_FIELD_NAME,
randomAlphaOfLengthBetween(1, 10));
CommonTermsQueryBuilder query = new CommonTermsQueryBuilder(fieldName, text.toString());

View File

@ -93,7 +93,7 @@ public class DisMaxQueryBuilderTests extends AbstractQueryTestCase<DisMaxQueryBu
" \"queries\":[\n" +
" {\n" +
" \"prefix\":{\n" +
" \"" + STRING_FIELD_NAME + "\":{\n" +
" \"" + TEXT_FIELD_NAME + "\":{\n" +
" \"value\":\"sh\",\n" +
" \"boost\":1.2\n" +
" }\n" +
@ -115,7 +115,7 @@ public class DisMaxQueryBuilderTests extends AbstractQueryTestCase<DisMaxQueryBu
assertThat(boostQuery.getQuery(), instanceOf(PrefixQuery.class));
PrefixQuery firstQ = (PrefixQuery) boostQuery.getQuery();
// since age is automatically registered in data, we encode it as numeric
assertThat(firstQ.getPrefix(), equalTo(new Term(STRING_FIELD_NAME, "sh")));
assertThat(firstQ.getPrefix(), equalTo(new Term(TEXT_FIELD_NAME, "sh")));
}

View File

@ -40,7 +40,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
@Override
protected FuzzyQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME);
FuzzyQueryBuilder query = new FuzzyQueryBuilder(fieldName, getRandomValueForFieldName(fieldName));
if (randomBoolean()) {
query.fuzziness(randomFuzziness(query.fieldName()));
@ -97,7 +97,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
public void testUnsupportedFuzzinessForStringType() throws IOException {
QueryShardContext context = createShardContext();
context.setAllowUnmappedFields(true);
FuzzyQueryBuilder fuzzyQueryBuilder = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text");
FuzzyQueryBuilder fuzzyQueryBuilder = new FuzzyQueryBuilder(TEXT_FIELD_NAME, "text");
fuzzyQueryBuilder.fuzziness(Fuzziness.build(randomFrom("a string which is not auto", "3h", "200s")));
NumberFormatException e = expectThrows(NumberFormatException.class, () -> fuzzyQueryBuilder.toQuery(context));
assertThat(e.getMessage(), containsString("For input string"));
@ -106,7 +106,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
public void testToQueryWithStringField() throws IOException {
String query = "{\n" +
" \"fuzzy\":{\n" +
" \"" + STRING_FIELD_NAME + "\":{\n" +
" \"" + TEXT_FIELD_NAME + "\":{\n" +
" \"value\":\"sh\",\n" +
" \"fuzziness\": \"AUTO\",\n" +
" \"prefix_length\":1,\n" +
@ -120,7 +120,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
assertThat(boostQuery.getBoost(), equalTo(2.0f));
assertThat(boostQuery.getQuery(), instanceOf(FuzzyQuery.class));
FuzzyQuery fuzzyQuery = (FuzzyQuery) boostQuery.getQuery();
assertThat(fuzzyQuery.getTerm(), equalTo(new Term(STRING_FIELD_NAME, "sh")));
assertThat(fuzzyQuery.getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "sh")));
assertThat(fuzzyQuery.getMaxEdits(), equalTo(Fuzziness.AUTO.asDistance("sh")));
assertThat(fuzzyQuery.getPrefixLength(), equalTo(1));
}
@ -128,7 +128,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
public void testToQueryWithStringFieldDefinedFuzziness() throws IOException {
String query = "{\n" +
" \"fuzzy\":{\n" +
" \"" + STRING_FIELD_NAME + "\":{\n" +
" \"" + TEXT_FIELD_NAME + "\":{\n" +
" \"value\":\"sh\",\n" +
" \"fuzziness\": \"AUTO:2,5\",\n" +
" \"prefix_length\":1,\n" +
@ -142,7 +142,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
assertThat(boostQuery.getBoost(), equalTo(2.0f));
assertThat(boostQuery.getQuery(), instanceOf(FuzzyQuery.class));
FuzzyQuery fuzzyQuery = (FuzzyQuery) boostQuery.getQuery();
assertThat(fuzzyQuery.getTerm(), equalTo(new Term(STRING_FIELD_NAME, "sh")));
assertThat(fuzzyQuery.getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "sh")));
assertThat(fuzzyQuery.getMaxEdits(), equalTo(1));
assertThat(fuzzyQuery.getPrefixLength(), equalTo(1));
}
@ -150,7 +150,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
public void testToQueryWithStringFieldDefinedWrongFuzziness() throws IOException {
String queryMissingFuzzinessUpLimit = "{\n" +
" \"fuzzy\":{\n" +
" \"" + STRING_FIELD_NAME + "\":{\n" +
" \"" + TEXT_FIELD_NAME + "\":{\n" +
" \"value\":\"sh\",\n" +
" \"fuzziness\": \"AUTO:2\",\n" +
" \"prefix_length\":1,\n" +
@ -165,7 +165,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
String queryHavingNegativeFuzzinessLowLimit = "{\n" +
" \"fuzzy\":{\n" +
" \"" + STRING_FIELD_NAME + "\":{\n" +
" \"" + TEXT_FIELD_NAME + "\":{\n" +
" \"value\":\"sh\",\n" +
" \"fuzziness\": \"AUTO:-1,6\",\n" +
" \"prefix_length\":1,\n" +
@ -181,7 +181,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
String queryMissingFuzzinessUpLimit2 = "{\n" +
" \"fuzzy\":{\n" +
" \"" + STRING_FIELD_NAME + "\":{\n" +
" \"" + TEXT_FIELD_NAME + "\":{\n" +
" \"value\":\"sh\",\n" +
" \"fuzziness\": \"AUTO:1,\",\n" +
" \"prefix_length\":1,\n" +
@ -195,7 +195,7 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
String queryMissingFuzzinessLowLimit = "{\n" +
" \"fuzzy\":{\n" +
" \"" + STRING_FIELD_NAME + "\":{\n" +
" \"" + TEXT_FIELD_NAME + "\":{\n" +
" \"value\":\"sh\",\n" +
" \"fuzziness\": \"AUTO:,5\",\n" +
" \"prefix_length\":1,\n" +
@ -294,15 +294,15 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
}
public void testToQueryWithTranspositions() throws Exception {
Query query = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text").toQuery(createShardContext());
Query query = new FuzzyQueryBuilder(TEXT_FIELD_NAME, "text").toQuery(createShardContext());
assertThat(query, instanceOf(FuzzyQuery.class));
assertEquals(FuzzyQuery.defaultTranspositions, ((FuzzyQuery)query).getTranspositions());
query = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text").transpositions(true).toQuery(createShardContext());
query = new FuzzyQueryBuilder(TEXT_FIELD_NAME, "text").transpositions(true).toQuery(createShardContext());
assertThat(query, instanceOf(FuzzyQuery.class));
assertEquals(true, ((FuzzyQuery)query).getTranspositions());
query = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text").transpositions(false).toQuery(createShardContext());
query = new FuzzyQueryBuilder(TEXT_FIELD_NAME, "text").transpositions(false).toQuery(createShardContext());
assertThat(query, instanceOf(FuzzyQuery.class));
assertEquals(false, ((FuzzyQuery)query).getTranspositions());
}

View File

@ -240,8 +240,8 @@ public abstract class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<Ge
ShapeType shapeType = ShapeType.randomType(random());
ShapeBuilder<?, ?, ?> shape = RandomShapeGenerator.createShapeWithin(random(), null, shapeType);
final GeoShapeQueryBuilder queryBuilder = randomBoolean() ?
new GeoShapeQueryBuilder(STRING_FIELD_NAME, shape) :
new GeoShapeQueryBuilder(STRING_FIELD_NAME, shape.buildGeometry());
new GeoShapeQueryBuilder(TEXT_FIELD_NAME, shape) :
new GeoShapeQueryBuilder(TEXT_FIELD_NAME, shape.buildGeometry());
QueryShardException e = expectThrows(QueryShardException.class, () -> queryBuilder.toQuery(createShardContext()));
assertThat(e.getMessage(), matchesPattern("Field \\[mapped_string\\] is of unsupported type \\[text\\]." +
" \\[geo_shape\\] query supports the following types \\[.*geo_shape.*\\]"));

View File

@ -56,7 +56,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
@Override
protected IntervalQueryBuilder doCreateTestQueryBuilder() {
return new IntervalQueryBuilder(STRING_FIELD_NAME, createRandomSource(0, true));
return new IntervalQueryBuilder(TEXT_FIELD_NAME, createRandomSource(0, true));
}
private static final String[] filters = new String[]{
@ -158,7 +158,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
@Override
public void testCacheability() throws IOException {
IntervalQueryBuilder queryBuilder = new IntervalQueryBuilder(STRING_FIELD_NAME, createRandomSource(0, false));
IntervalQueryBuilder queryBuilder = new IntervalQueryBuilder(TEXT_FIELD_NAME, createRandomSource(0, false));
QueryShardContext context = createShardContext();
QueryBuilder rewriteQuery = rewriteQuery(queryBuilder, new QueryShardContext(context));
assertNotNull(rewriteQuery.toQuery(context));
@ -168,7 +168,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
new Script(ScriptType.INLINE, "mockscript", "1", Collections.emptyMap())
);
IntervalsSourceProvider source = new IntervalsSourceProvider.Match("text", 0, true, "simple", scriptFilter, null);
queryBuilder = new IntervalQueryBuilder(STRING_FIELD_NAME, source);
queryBuilder = new IntervalQueryBuilder(TEXT_FIELD_NAME, source);
rewriteQuery = rewriteQuery(queryBuilder, new QueryShardContext(context));
assertNotNull(rewriteQuery.toQuery(context));
assertFalse("query with scripts should not be cacheable: " + queryBuilder.toString(), context.isCacheable());
@ -185,47 +185,47 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
return super.mutateInstance(instance); // just change name/boost
}
if (randomBoolean()) {
return new IntervalQueryBuilder(STRING_FIELD_NAME_2, instance.getSourceProvider());
return new IntervalQueryBuilder(KEYWORD_FIELD_NAME, instance.getSourceProvider());
}
return new IntervalQueryBuilder(STRING_FIELD_NAME, createRandomSource(0, true));
return new IntervalQueryBuilder(TEXT_FIELD_NAME, createRandomSource(0, true));
}
public void testMatchInterval() throws IOException {
String json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\" : { \"match\" : { \"query\" : \"Hello world\" } } } }";
"{ \"" + TEXT_FIELD_NAME + "\" : { \"match\" : { \"query\" : \"Hello world\" } } } }";
IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
Query expected = new IntervalQuery(STRING_FIELD_NAME,
Query expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.unordered(Intervals.term("hello"), Intervals.term("world")));
assertEquals(expected, builder.toQuery(createShardContext()));
json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\" : { " +
"{ \"" + TEXT_FIELD_NAME + "\" : { " +
" \"match\" : { " +
" \"query\" : \"Hello world\"," +
" \"max_gaps\" : 40 } } } }";
builder = (IntervalQueryBuilder) parseQuery(json);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.maxgaps(40, Intervals.unordered(Intervals.term("hello"), Intervals.term("world"))));
assertEquals(expected, builder.toQuery(createShardContext()));
json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\" : { " +
"{ \"" + TEXT_FIELD_NAME + "\" : { " +
" \"match\" : { " +
" \"query\" : \"Hello world\"," +
" \"ordered\" : true }," +
" \"boost\" : 2 } } }";
builder = (IntervalQueryBuilder) parseQuery(json);
expected = new BoostQuery(new IntervalQuery(STRING_FIELD_NAME,
expected = new BoostQuery(new IntervalQuery(TEXT_FIELD_NAME,
Intervals.ordered(Intervals.term("hello"), Intervals.term("world"))), 2);
assertEquals(expected, builder.toQuery(createShardContext()));
json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\" : { " +
"{ \"" + TEXT_FIELD_NAME + "\" : { " +
" \"match\" : { " +
" \"query\" : \"Hello world\"," +
" \"max_gaps\" : 10," +
@ -233,12 +233,12 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
" \"ordered\" : true } } } }";
builder = (IntervalQueryBuilder) parseQuery(json);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.maxgaps(10, Intervals.ordered(Intervals.term("Hello"), Intervals.term("world"))));
assertEquals(expected, builder.toQuery(createShardContext()));
json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\" : { " +
"{ \"" + TEXT_FIELD_NAME + "\" : { " +
" \"match\" : { " +
" \"query\" : \"Hello world\"," +
" \"max_gaps\" : 10," +
@ -247,13 +247,13 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
" \"ordered\" : true } } } }";
builder = (IntervalQueryBuilder) parseQuery(json);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.fixField(MASKED_FIELD,
Intervals.maxgaps(10, Intervals.ordered(Intervals.term("Hello"), Intervals.term("world")))));
assertEquals(expected, builder.toQuery(createShardContext()));
json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\" : { " +
"{ \"" + TEXT_FIELD_NAME + "\" : { " +
" \"match\" : { " +
" \"query\" : \"Hello world\"," +
" \"max_gaps\" : 10," +
@ -264,7 +264,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
" \"match\" : { \"query\" : \"blah\" } } } } } } }";
builder = (IntervalQueryBuilder) parseQuery(json);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.containing(Intervals.maxgaps(10, Intervals.ordered(Intervals.term("Hello"), Intervals.term("world"))),
Intervals.term("blah")));
assertEquals(expected, builder.toQuery(createShardContext()));
@ -272,17 +272,17 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
public void testOrInterval() throws IOException {
String json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": {" +
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": {" +
" \"any_of\" : { " +
" \"intervals\" : [" +
" { \"match\" : { \"query\" : \"one\" } }," +
" { \"match\" : { \"query\" : \"two\" } } ] } } } }";
IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
Query expected = new IntervalQuery(STRING_FIELD_NAME,
Query expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.or(Intervals.term("one"), Intervals.term("two")));
assertEquals(expected, builder.toQuery(createShardContext()));
json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": {" +
json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": {" +
" \"any_of\" : { " +
" \"intervals\" : [" +
" { \"match\" : { \"query\" : \"one\" } }," +
@ -290,7 +290,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
" \"filter\" : {" +
" \"not_containing\" : { \"match\" : { \"query\" : \"three\" } } } } } } }";
builder = (IntervalQueryBuilder) parseQuery(json);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.notContaining(
Intervals.or(Intervals.term("one"), Intervals.term("two")),
Intervals.term("three")));
@ -299,7 +299,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
public void testCombineInterval() throws IOException {
String json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": {" +
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": {" +
" \"all_of\" : {" +
" \"ordered\" : true," +
" \"intervals\" : [" +
@ -317,7 +317,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
" \"analyzer\" : \"keyword\" } } } }," +
" \"boost\" : 1.5 } } }";
IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
Query expected = new BoostQuery(new IntervalQuery(STRING_FIELD_NAME,
Query expected = new BoostQuery(new IntervalQuery(TEXT_FIELD_NAME,
Intervals.containedBy(
Intervals.maxgaps(30, Intervals.ordered(
Intervals.term("one"),
@ -329,7 +329,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
public void testCombineDisjunctionInterval() throws IOException {
String json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\": { " +
"{ \"" + TEXT_FIELD_NAME + "\": { " +
" \"all_of\" : {" +
" \"ordered\" : true," +
" \"intervals\" : [" +
@ -344,7 +344,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
" \"match\" : { \"query\" : \"freeze\" } } } } } } }";
IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
Query expected = new IntervalQuery(STRING_FIELD_NAME,
Query expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.notContainedBy(
Intervals.maxgaps(30, Intervals.ordered(
Intervals.term("atmosphere"),
@ -374,7 +374,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
+ NO_POSITIONS_FIELD + "] with no positions indexed"));
String json = "{ \"intervals\" : " +
"{ \"" + STRING_FIELD_NAME + "\" : { " +
"{ \"" + TEXT_FIELD_NAME + "\" : { " +
" \"match\" : { " +
" \"query\" : \"Hello world\"," +
" \"max_gaps\" : 10," +
@ -391,7 +391,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
}
public void testMultipleProviders() {
String json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"boost\" : 1," +
"\"match\" : { \"query\" : \"term1\" }," +
"\"all_of\" : { \"intervals\" : [ { \"query\" : \"term2\" } ] } }";
@ -426,7 +426,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
BigArrays.NON_RECYCLING_INSTANCE, null, null, baseContext.getMapperService(),
null, scriptService, null, null, null, null, null, null, null, () -> true);
String json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"match\" : { " +
" \"query\" : \"term1\"," +
" \"filter\" : { " +
@ -437,7 +437,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
Query q = builder.toQuery(context);
IntervalQuery expected = new IntervalQuery(STRING_FIELD_NAME,
IntervalQuery expected = new IntervalQuery(TEXT_FIELD_NAME,
new IntervalsSourceProvider.ScriptFilterSource(Intervals.term("term1"), "interval.start > 3", null));
assertEquals(expected, q);
@ -445,10 +445,10 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
public void testPrefixes() throws IOException {
String json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"prefix\" : { \"prefix\" : \"term\" } } } }";
IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
Query expected = new IntervalQuery(STRING_FIELD_NAME, Intervals.prefix(new BytesRef("term")));
Query expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.prefix(new BytesRef("term")));
assertEquals(expected, builder.toQuery(createShardContext()));
String no_positions_json = "{ \"intervals\" : { \"" + NO_POSITIONS_FIELD + "\": { " +
@ -458,7 +458,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
builder1.toQuery(createShardContext());
});
String no_positions_fixed_field_json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String no_positions_fixed_field_json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"prefix\" : { \"prefix\" : \"term\", \"use_field\" : \"" + NO_POSITIONS_FIELD + "\" } } } }";
expectThrows(IllegalArgumentException.class, () -> {
IntervalQueryBuilder builder1 = (IntervalQueryBuilder) parseQuery(no_positions_fixed_field_json);
@ -479,11 +479,11 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
Intervals.term("t")));
assertEquals(expected, builder.toQuery(createShardContext()));
String fix_field_prefix_json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String fix_field_prefix_json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"prefix\" : { \"prefix\" : \"term\", \"use_field\" : \"" + PREFIXED_FIELD + "\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(fix_field_prefix_json);
// This looks weird, but it's fine, because the innermost fixField wins
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.fixField(PREFIXED_FIELD, Intervals.fixField(PREFIXED_FIELD + "._index_prefix", Intervals.term("term"))));
assertEquals(expected, builder.toQuery(createShardContext()));
@ -493,21 +493,21 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
expected = new IntervalQuery(PREFIXED_FIELD, Intervals.fixField(PREFIXED_FIELD + "._index_prefix", Intervals.term("Term")));
assertEquals(expected, builder.toQuery(createShardContext()));
String keyword_fix_field_json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String keyword_fix_field_json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"prefix\" : { \"prefix\" : \"Term\", \"analyzer\" : \"keyword\", \"use_field\" : \"" + PREFIXED_FIELD + "\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(keyword_fix_field_json);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
Intervals.fixField(PREFIXED_FIELD, Intervals.fixField(PREFIXED_FIELD + "._index_prefix", Intervals.term("Term"))));
assertEquals(expected, builder.toQuery(createShardContext()));
}
public void testWildcard() throws IOException {
String json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"wildcard\" : { \"pattern\" : \"Te?m\" } } } }";
IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
Query expected = new IntervalQuery(STRING_FIELD_NAME, Intervals.wildcard(new BytesRef("te?m")));
Query expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.wildcard(new BytesRef("te?m")));
assertEquals(expected, builder.toQuery(createShardContext()));
String no_positions_json = "{ \"intervals\" : { \"" + NO_POSITIONS_FIELD + "\": { " +
@ -517,32 +517,32 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
builder1.toQuery(createShardContext());
});
String keyword_json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String keyword_json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"wildcard\" : { \"pattern\" : \"Te?m\", \"analyzer\" : \"keyword\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(keyword_json);
expected = new IntervalQuery(STRING_FIELD_NAME, Intervals.wildcard(new BytesRef("Te?m")));
expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.wildcard(new BytesRef("Te?m")));
assertEquals(expected, builder.toQuery(createShardContext()));
String fixed_field_json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String fixed_field_json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"wildcard\" : { \"pattern\" : \"Te?m\", \"use_field\" : \"masked_field\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(fixed_field_json);
expected = new IntervalQuery(STRING_FIELD_NAME, Intervals.fixField(MASKED_FIELD, Intervals.wildcard(new BytesRef("te?m"))));
expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.fixField(MASKED_FIELD, Intervals.wildcard(new BytesRef("te?m"))));
assertEquals(expected, builder.toQuery(createShardContext()));
String fixed_field_json_no_positions = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String fixed_field_json_no_positions = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"wildcard\" : { \"pattern\" : \"Te?m\", \"use_field\" : \"" + NO_POSITIONS_FIELD + "\" } } } }";
expectThrows(IllegalArgumentException.class, () -> {
IntervalQueryBuilder builder1 = (IntervalQueryBuilder) parseQuery(fixed_field_json_no_positions);
builder1.toQuery(createShardContext());
});
String fixed_field_analyzer_json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String fixed_field_analyzer_json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"wildcard\" : { \"pattern\" : \"Te?m\", \"use_field\" : \"masked_field\", \"analyzer\" : \"keyword\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(fixed_field_analyzer_json);
expected = new IntervalQuery(STRING_FIELD_NAME, Intervals.fixField(MASKED_FIELD,
expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.fixField(MASKED_FIELD,
Intervals.wildcard(new BytesRef("Te?m"))));
assertEquals(expected, builder.toQuery(createShardContext()));
}
@ -555,47 +555,47 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
public void testFuzzy() throws IOException {
String json = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"fuzzy\" : { \"term\" : \"Term\" } } } }";
IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
Query expected = new IntervalQuery(STRING_FIELD_NAME,
Query expected = new IntervalQuery(TEXT_FIELD_NAME,
buildFuzzySource("term", "Term", FuzzyQueryBuilder.DEFAULT_PREFIX_LENGTH, true, Fuzziness.AUTO.asDistance("term")));
assertEquals(expected, builder.toQuery(createShardContext()));
String json_with_prefix = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json_with_prefix = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"fuzzy\" : { \"term\" : \"Term\", \"prefix_length\" : 2 } } } }";
builder = (IntervalQueryBuilder) parseQuery(json_with_prefix);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
buildFuzzySource("term", "Term", 2, true, Fuzziness.AUTO.asDistance("term")));
assertEquals(expected, builder.toQuery(createShardContext()));
String json_with_fuzziness = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json_with_fuzziness = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"fuzzy\" : { \"term\" : \"Term\", \"prefix_length\" : 2, \"fuzziness\" : \"1\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(json_with_fuzziness);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
buildFuzzySource("term", "Term", 2, true, Fuzziness.ONE.asDistance("term")));
assertEquals(expected, builder.toQuery(createShardContext()));
String json_no_transpositions = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json_no_transpositions = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"fuzzy\" : { \"term\" : \"Term\", \"prefix_length\" : 2, \"transpositions\" : false } } } }";
builder = (IntervalQueryBuilder) parseQuery(json_no_transpositions);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
buildFuzzySource("term", "Term", 2, false, Fuzziness.AUTO.asDistance("term")));
assertEquals(expected, builder.toQuery(createShardContext()));
String json_with_analyzer = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json_with_analyzer = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"fuzzy\" : { \"term\" : \"Term\", \"prefix_length\" : 2, \"analyzer\" : \"keyword\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(json_with_analyzer);
expected = new IntervalQuery(STRING_FIELD_NAME,
expected = new IntervalQuery(TEXT_FIELD_NAME,
buildFuzzySource("Term", "Term", 2, true, Fuzziness.AUTO.asDistance("term")));
assertEquals(expected, builder.toQuery(createShardContext()));
String json_with_fixfield = "{ \"intervals\" : { \"" + STRING_FIELD_NAME + "\": { " +
String json_with_fixfield = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " +
"\"fuzzy\" : { \"term\" : \"Term\", \"prefix_length\" : 2, \"fuzziness\" : \"1\", " +
"\"use_field\" : \"" + MASKED_FIELD + "\" } } } }";
builder = (IntervalQueryBuilder) parseQuery(json_with_fixfield);
expected = new IntervalQuery(STRING_FIELD_NAME, Intervals.fixField(MASKED_FIELD,
expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.fixField(MASKED_FIELD,
buildFuzzySource("term", "Term", 2, true, Fuzziness.ONE.asDistance("term"))));
assertEquals(expected, builder.toQuery(createShardContext()));

View File

@ -54,7 +54,7 @@ public class MatchBoolPrefixQueryBuilderTests extends AbstractQueryTestCase<Matc
@Override
protected MatchBoolPrefixQueryBuilder doCreateTestQueryBuilder() {
final String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
final String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME);
final Object value = IntStream.rangeClosed(0, randomIntBetween(0, 3))
.mapToObj(i -> randomAlphaOfLengthBetween(1, 10) + " ")
.collect(Collectors.joining())
@ -243,32 +243,32 @@ public class MatchBoolPrefixQueryBuilderTests extends AbstractQueryTestCase<Matc
}
public void testAnalysis() throws Exception {
final MatchBoolPrefixQueryBuilder builder = new MatchBoolPrefixQueryBuilder(STRING_FIELD_NAME, "foo bar baz");
final MatchBoolPrefixQueryBuilder builder = new MatchBoolPrefixQueryBuilder(TEXT_FIELD_NAME, "foo bar baz");
final Query query = builder.toQuery(createShardContext());
assertBooleanQuery(query, asList(
new TermQuery(new Term(STRING_FIELD_NAME, "foo")),
new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
new PrefixQuery(new Term(STRING_FIELD_NAME, "baz"))
new TermQuery(new Term(TEXT_FIELD_NAME, "foo")),
new TermQuery(new Term(TEXT_FIELD_NAME, "bar")),
new PrefixQuery(new Term(TEXT_FIELD_NAME, "baz"))
));
}
public void testAnalysisSynonym() throws Exception {
final MatchQuery matchQuery = new MatchQuery(createShardContext());
matchQuery.setAnalyzer(new MockSynonymAnalyzer());
final Query query = matchQuery.parse(MatchQuery.Type.BOOLEAN_PREFIX, STRING_FIELD_NAME, "fox dogs red");
final Query query = matchQuery.parse(MatchQuery.Type.BOOLEAN_PREFIX, TEXT_FIELD_NAME, "fox dogs red");
assertBooleanQuery(query, asList(
new TermQuery(new Term(STRING_FIELD_NAME, "fox")),
new SynonymQuery(new Term(STRING_FIELD_NAME, "dogs"), new Term(STRING_FIELD_NAME, "dog")),
new PrefixQuery(new Term(STRING_FIELD_NAME, "red"))
new TermQuery(new Term(TEXT_FIELD_NAME, "fox")),
new SynonymQuery(new Term(TEXT_FIELD_NAME, "dogs"), new Term(TEXT_FIELD_NAME, "dog")),
new PrefixQuery(new Term(TEXT_FIELD_NAME, "red"))
));
}
public void testAnalysisSingleTerm() throws Exception {
final MatchBoolPrefixQueryBuilder builder = new MatchBoolPrefixQueryBuilder(STRING_FIELD_NAME, "foo");
final MatchBoolPrefixQueryBuilder builder = new MatchBoolPrefixQueryBuilder(TEXT_FIELD_NAME, "foo");
final Query query = builder.toQuery(createShardContext());
assertThat(query, equalTo(new PrefixQuery(new Term(STRING_FIELD_NAME, "foo"))));
assertThat(query, equalTo(new PrefixQuery(new Term(TEXT_FIELD_NAME, "foo"))));
}
private static void assertBooleanQuery(Query actual, List<Query> expectedClauseQueries) {

View File

@ -38,7 +38,7 @@ import static org.hamcrest.Matchers.notNullValue;
public class MatchPhrasePrefixQueryBuilderTests extends AbstractQueryTestCase<MatchPhrasePrefixQueryBuilder> {
@Override
protected MatchPhrasePrefixQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME);
Object value;
if (isTextField(fieldName)) {
int terms = randomIntBetween(0, 3);

View File

@ -44,7 +44,7 @@ import static org.hamcrest.Matchers.notNullValue;
public class MatchPhraseQueryBuilderTests extends AbstractQueryTestCase<MatchPhraseQueryBuilder> {
@Override
protected MatchPhraseQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME, INT_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME, INT_FIELD_NAME,
DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
Object value;
if (isTextField(fieldName)) {

View File

@ -70,7 +70,7 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
@Override
protected MatchQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME, INT_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME, INT_FIELD_NAME,
DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
Object value;
if (isTextField(fieldName)) {
@ -402,15 +402,15 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
{
matchQuery.setAutoGenerateSynonymsPhraseQuery(false);
final Query query = matchQuery.parse(Type.BOOLEAN, STRING_FIELD_NAME, "guinea pig");
final Query query = matchQuery.parse(Type.BOOLEAN, TEXT_FIELD_NAME, "guinea pig");
final Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "guinea")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "pig")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "guinea")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "pig")), BooleanClause.Occur.MUST)
.build(),
BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "cavy")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "cavy")), BooleanClause.Occur.SHOULD)
.build(),
BooleanClause.Occur.SHOULD).build();
assertThat(query, equalTo(expectedQuery));
@ -418,15 +418,15 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
{
matchQuery.setAutoGenerateSynonymsPhraseQuery(true);
final Query query = matchQuery.parse(Type.BOOLEAN, STRING_FIELD_NAME, "guinea pig");
final Query query = matchQuery.parse(Type.BOOLEAN, TEXT_FIELD_NAME, "guinea pig");
final Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "guinea"))
.add(new Term(STRING_FIELD_NAME, "pig"))
.add(new Term(TEXT_FIELD_NAME, "guinea"))
.add(new Term(TEXT_FIELD_NAME, "pig"))
.build(),
BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "cavy")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "cavy")), BooleanClause.Occur.SHOULD)
.build(),
BooleanClause.Occur.SHOULD).build();
assertThat(query, equalTo(expectedQuery));
@ -434,15 +434,15 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
{
matchQuery.setAutoGenerateSynonymsPhraseQuery(false);
final Query query = matchQuery.parse(Type.BOOLEAN_PREFIX, STRING_FIELD_NAME, "guinea pig");
final Query query = matchQuery.parse(Type.BOOLEAN_PREFIX, TEXT_FIELD_NAME, "guinea pig");
final Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "guinea")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "pig")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "guinea")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "pig")), BooleanClause.Occur.MUST)
.build(),
BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "cavy")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "cavy")), BooleanClause.Occur.SHOULD)
.build(),
BooleanClause.Occur.SHOULD).build();
assertThat(query, equalTo(expectedQuery));
@ -450,12 +450,12 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
{
matchQuery.setAutoGenerateSynonymsPhraseQuery(true);
final Query query = matchQuery.parse(Type.BOOLEAN_PREFIX, STRING_FIELD_NAME, "guinea pig");
final MultiPhrasePrefixQuery guineaPig = new MultiPhrasePrefixQuery(STRING_FIELD_NAME);
guineaPig.add(new Term(STRING_FIELD_NAME, "guinea"));
guineaPig.add(new Term(STRING_FIELD_NAME, "pig"));
final MultiPhrasePrefixQuery cavy = new MultiPhrasePrefixQuery(STRING_FIELD_NAME);
cavy.add(new Term(STRING_FIELD_NAME, "cavy"));
final Query query = matchQuery.parse(Type.BOOLEAN_PREFIX, TEXT_FIELD_NAME, "guinea pig");
final MultiPhrasePrefixQuery guineaPig = new MultiPhrasePrefixQuery(TEXT_FIELD_NAME);
guineaPig.add(new Term(TEXT_FIELD_NAME, "guinea"));
guineaPig.add(new Term(TEXT_FIELD_NAME, "pig"));
final MultiPhrasePrefixQuery cavy = new MultiPhrasePrefixQuery(TEXT_FIELD_NAME);
cavy.add(new Term(TEXT_FIELD_NAME, "cavy"));
final Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(guineaPig, BooleanClause.Occur.SHOULD)
@ -469,21 +469,21 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
public void testMultiWordSynonymsPhrase() throws Exception {
final MatchQuery matchQuery = new MatchQuery(createShardContext());
matchQuery.setAnalyzer(new MockSynonymAnalyzer());
final Query actual = matchQuery.parse(Type.PHRASE, STRING_FIELD_NAME, "guinea pig dogs");
Query expected = SpanNearQuery.newOrderedNearQuery(STRING_FIELD_NAME)
final Query actual = matchQuery.parse(Type.PHRASE, TEXT_FIELD_NAME, "guinea pig dogs");
Query expected = SpanNearQuery.newOrderedNearQuery(TEXT_FIELD_NAME)
.addClause(
new SpanOrQuery(new SpanQuery[]{
SpanNearQuery.newOrderedNearQuery(STRING_FIELD_NAME)
.addClause(new SpanTermQuery(new Term(STRING_FIELD_NAME, "guinea")))
.addClause(new SpanTermQuery(new Term(STRING_FIELD_NAME, "pig")))
SpanNearQuery.newOrderedNearQuery(TEXT_FIELD_NAME)
.addClause(new SpanTermQuery(new Term(TEXT_FIELD_NAME, "guinea")))
.addClause(new SpanTermQuery(new Term(TEXT_FIELD_NAME, "pig")))
.setSlop(0)
.build(),
new SpanTermQuery(new Term(STRING_FIELD_NAME, "cavy"))
new SpanTermQuery(new Term(TEXT_FIELD_NAME, "cavy"))
})
)
.addClause(new SpanOrQuery(new SpanQuery[]{
new SpanTermQuery(new Term(STRING_FIELD_NAME, "dogs")),
new SpanTermQuery(new Term(STRING_FIELD_NAME, "dog"))
new SpanTermQuery(new Term(TEXT_FIELD_NAME, "dogs")),
new SpanTermQuery(new Term(TEXT_FIELD_NAME, "dog"))
}))
.build();
assertEquals(expected, actual);
@ -493,10 +493,10 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
public void testAliasWithSynonyms() throws Exception {
final MatchQuery matchQuery = new MatchQuery(createShardContext());
matchQuery.setAnalyzer(new MockSynonymAnalyzer());
final Query actual = matchQuery.parse(Type.PHRASE, STRING_ALIAS_FIELD_NAME, "dogs");
Query expected = new SynonymQuery.Builder(STRING_FIELD_NAME)
.addTerm(new Term(STRING_FIELD_NAME, "dogs"))
.addTerm(new Term(STRING_FIELD_NAME, "dog"))
final Query actual = matchQuery.parse(Type.PHRASE, TEXT_ALIAS_FIELD_NAME, "dogs");
Query expected = new SynonymQuery.Builder(TEXT_FIELD_NAME)
.addTerm(new Term(TEXT_FIELD_NAME, "dogs"))
.addTerm(new Term(TEXT_FIELD_NAME, "dog"))
.build();
assertEquals(expected, actual);
}
@ -504,9 +504,9 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
public void testMaxBooleanClause() {
MatchQuery query = new MatchQuery(createShardContext());
query.setAnalyzer(new MockGraphAnalyzer(createGiantGraph(40)));
expectThrows(BooleanQuery.TooManyClauses.class, () -> query.parse(Type.PHRASE, STRING_FIELD_NAME, ""));
expectThrows(BooleanQuery.TooManyClauses.class, () -> query.parse(Type.PHRASE, TEXT_FIELD_NAME, ""));
query.setAnalyzer(new MockGraphAnalyzer(createGiantGraphMultiTerms()));
expectThrows(BooleanQuery.TooManyClauses.class, () -> query.parse(Type.PHRASE, STRING_FIELD_NAME, ""));
expectThrows(BooleanQuery.TooManyClauses.class, () -> query.parse(Type.PHRASE, TEXT_FIELD_NAME, ""));
}
private static class MockGraphAnalyzer extends Analyzer {

View File

@ -87,7 +87,7 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase<MoreLik
}
private static String[] randomStringFields() {
String[] mappedStringFields = new String[]{STRING_FIELD_NAME, STRING_FIELD_NAME_2, STRING_ALIAS_FIELD_NAME};
String[] mappedStringFields = new String[]{TEXT_FIELD_NAME, KEYWORD_FIELD_NAME, TEXT_ALIAS_FIELD_NAME};
String[] unmappedStringFields = generateRandomStringArray(2, 5, false, false);
return Stream.concat(Arrays.stream(mappedStringFields), Arrays.stream(unmappedStringFields)).toArray(String[]::new);
}
@ -321,7 +321,7 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase<MoreLik
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index",
context.getIndexSettings().getSettings(),
Settings.builder().putList("index.query.default_field", STRING_FIELD_NAME).build()
Settings.builder().putList("index.query.default_field", TEXT_FIELD_NAME).build()
)
);
try {

View File

@ -65,11 +65,11 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
@Override
protected MultiMatchQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(STRING_FIELD_NAME, INT_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME, INT_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME,
MISSING_FIELD_NAME, MISSING_WILDCARD_FIELD_NAME);
final Object value;
if (fieldName.equals(STRING_FIELD_NAME)) {
if (fieldName.equals(TEXT_FIELD_NAME)) {
value = getRandomQueryText();
} else {
value = getRandomValueForFieldName(fieldName);
@ -92,7 +92,7 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
// sets other parameters of the multi match query
if (randomBoolean()) {
if (fieldName.equals(STRING_FIELD_NAME) || fieldName.equals(STRING_ALIAS_FIELD_NAME) || fieldName.equals(STRING_FIELD_NAME_2)) {
if (fieldName.equals(TEXT_FIELD_NAME) || fieldName.equals(TEXT_ALIAS_FIELD_NAME) || fieldName.equals(KEYWORD_FIELD_NAME)) {
query.type(randomFrom(MultiMatchQueryBuilder.Type.values()));
} else {
query.type(randomValueOtherThanMany(
@ -103,13 +103,13 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
if (randomBoolean()) {
query.operator(randomFrom(Operator.values()));
}
if (randomBoolean() && fieldName.equals(STRING_FIELD_NAME)) {
if (randomBoolean() && fieldName.equals(TEXT_FIELD_NAME)) {
query.analyzer(randomAnalyzer());
}
if (randomBoolean() && query.type() != Type.BOOL_PREFIX) {
query.slop(randomIntBetween(0, 5));
}
if (fieldName.equals(STRING_FIELD_NAME) && randomBoolean() &&
if (fieldName.equals(TEXT_FIELD_NAME) && randomBoolean() &&
(query.type() == Type.BEST_FIELDS || query.type() == Type.MOST_FIELDS)) {
query.fuzziness(randomFuzziness(fieldName));
}
@ -184,50 +184,50 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
public void testToQueryBoost() throws IOException {
QueryShardContext shardContext = createShardContext();
MultiMatchQueryBuilder multiMatchQueryBuilder = new MultiMatchQueryBuilder("test");
multiMatchQueryBuilder.field(STRING_FIELD_NAME, 5f);
multiMatchQueryBuilder.field(TEXT_FIELD_NAME, 5f);
Query query = multiMatchQueryBuilder.toQuery(shardContext);
assertTermOrBoostQuery(query, STRING_FIELD_NAME, "test", 5f);
assertTermOrBoostQuery(query, TEXT_FIELD_NAME, "test", 5f);
multiMatchQueryBuilder = new MultiMatchQueryBuilder("test");
multiMatchQueryBuilder.field(STRING_FIELD_NAME, 5f);
multiMatchQueryBuilder.field(TEXT_FIELD_NAME, 5f);
multiMatchQueryBuilder.boost(2f);
query = multiMatchQueryBuilder.toQuery(shardContext);
assertThat(query, instanceOf(BoostQuery.class));
BoostQuery boostQuery = (BoostQuery) query;
assertThat(boostQuery.getBoost(), equalTo(2f));
assertTermOrBoostQuery(boostQuery.getQuery(), STRING_FIELD_NAME, "test", 5f);
assertTermOrBoostQuery(boostQuery.getQuery(), TEXT_FIELD_NAME, "test", 5f);
}
public void testToQueryMultipleTermsBooleanQuery() throws Exception {
Query query = multiMatchQuery("test1 test2").field(STRING_FIELD_NAME).toQuery(createShardContext());
Query query = multiMatchQuery("test1 test2").field(TEXT_FIELD_NAME).toQuery(createShardContext());
assertThat(query, instanceOf(BooleanQuery.class));
BooleanQuery bQuery = (BooleanQuery) query;
assertThat(bQuery.clauses().size(), equalTo(2));
assertThat(assertBooleanSubQuery(query, TermQuery.class, 0).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test1")));
assertThat(assertBooleanSubQuery(query, TermQuery.class, 1).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test2")));
assertThat(assertBooleanSubQuery(query, TermQuery.class, 0).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "test1")));
assertThat(assertBooleanSubQuery(query, TermQuery.class, 1).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "test2")));
}
public void testToQueryMultipleFieldsDisableDismax() throws Exception {
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).tieBreaker(1.0f)
Query query = multiMatchQuery("test").field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME).tieBreaker(1.0f)
.toQuery(createShardContext());
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
assertThat(dQuery.getTieBreakerMultiplier(), equalTo(1.0f));
assertThat(dQuery.getDisjuncts().size(), equalTo(2));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 0).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 1).getTerm(), equalTo(new Term(STRING_FIELD_NAME_2, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 0).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 1).getTerm(), equalTo(new Term(KEYWORD_FIELD_NAME, "test")));
}
public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).toQuery(createShardContext());
Query query = multiMatchQuery("test").field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME).toQuery(createShardContext());
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) query;
assertThat(disMaxQuery.getTieBreakerMultiplier(), equalTo(0.0f));
List<Query> disjuncts = disMaxQuery.getDisjuncts();
assertThat(disjuncts.get(0), instanceOf(TermQuery.class));
assertThat(((TermQuery) disjuncts.get(0)).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test")));
assertThat(((TermQuery) disjuncts.get(0)).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "test")));
assertThat(disjuncts.get(1), instanceOf(TermQuery.class));
assertThat(((TermQuery) disjuncts.get(1)).getTerm(), equalTo(new Term(STRING_FIELD_NAME_2, "test")));
assertThat(((TermQuery) disjuncts.get(1)).getTerm(), equalTo(new Term(KEYWORD_FIELD_NAME, "test")));
}
public void testToQueryFieldsWildcard() throws Exception {
@ -236,8 +236,8 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
assertThat(dQuery.getTieBreakerMultiplier(), equalTo(1.0f));
assertThat(dQuery.getDisjuncts().size(), equalTo(2));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 0).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 1).getTerm(), equalTo(new Term(STRING_FIELD_NAME_2, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 0).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 1).getTerm(), equalTo(new Term(KEYWORD_FIELD_NAME, "test")));
}
public void testToQueryFieldMissing() throws Exception {
@ -248,20 +248,19 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
}
public void testToQueryBooleanPrefixSingleField() throws IOException {
final MultiMatchQueryBuilder builder = new MultiMatchQueryBuilder("foo bar", STRING_FIELD_NAME);
final MultiMatchQueryBuilder builder = new MultiMatchQueryBuilder("foo bar", TEXT_FIELD_NAME);
builder.type(Type.BOOL_PREFIX);
final Query query = builder.toQuery(createShardContext());
assertThat(query, instanceOf(BooleanQuery.class));
final BooleanQuery booleanQuery = (BooleanQuery) query;
assertThat(booleanQuery.clauses(), hasSize(2));
assertThat(assertBooleanSubQuery(booleanQuery, TermQuery.class, 0).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "foo")));
assertThat(assertBooleanSubQuery(booleanQuery, PrefixQuery.class, 1).getPrefix(), equalTo(new Term(STRING_FIELD_NAME, "bar")));
assertThat(assertBooleanSubQuery(booleanQuery, TermQuery.class, 0).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "foo")));
assertThat(assertBooleanSubQuery(booleanQuery, PrefixQuery.class, 1).getPrefix(), equalTo(new Term(TEXT_FIELD_NAME, "bar")));
}
public void testToQueryBooleanPrefixMultipleFields() throws IOException {
{
// STRING_FIELD_NAME_2 is a keyword field
final MultiMatchQueryBuilder queryBuilder = new MultiMatchQueryBuilder("foo bar", STRING_FIELD_NAME, STRING_FIELD_NAME_2);
final MultiMatchQueryBuilder queryBuilder = new MultiMatchQueryBuilder("foo bar", TEXT_FIELD_NAME, KEYWORD_FIELD_NAME);
queryBuilder.type(Type.BOOL_PREFIX);
final Query query = queryBuilder.toQuery(createShardContext());
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
@ -269,9 +268,9 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
assertThat(disMaxQuery.getDisjuncts(), hasSize(2));
final BooleanQuery firstDisjunct = assertDisjunctionSubQuery(disMaxQuery, BooleanQuery.class, 0);
assertThat(firstDisjunct.clauses(), hasSize(2));
assertThat(assertBooleanSubQuery(firstDisjunct, TermQuery.class, 0).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "foo")));
assertThat(assertBooleanSubQuery(firstDisjunct, TermQuery.class, 0).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "foo")));
final PrefixQuery secondDisjunct = assertDisjunctionSubQuery(disMaxQuery, PrefixQuery.class, 1);
assertThat(secondDisjunct.getPrefix(), equalTo(new Term(STRING_FIELD_NAME_2, "foo bar")));
assertThat(secondDisjunct.getPrefix(), equalTo(new Term(KEYWORD_FIELD_NAME, "foo bar")));
}
}
@ -367,14 +366,14 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
}
public void testToFuzzyQuery() throws Exception {
MultiMatchQueryBuilder qb = new MultiMatchQueryBuilder("text").field(STRING_FIELD_NAME);
MultiMatchQueryBuilder qb = new MultiMatchQueryBuilder("text").field(TEXT_FIELD_NAME);
qb.fuzziness(Fuzziness.TWO);
qb.prefixLength(2);
qb.maxExpansions(5);
qb.fuzzyTranspositions(false);
Query query = qb.toQuery(createShardContext());
FuzzyQuery expected = new FuzzyQuery(new Term(STRING_FIELD_NAME, "text"), 2, 2,
FuzzyQuery expected = new FuzzyQuery(new Term(TEXT_FIELD_NAME, "text"), 2, 2,
5, false);
assertEquals(expected, query);
@ -391,7 +390,7 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
// `*` is in the list of the default_field => leniency set to true
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(), Settings.builder().putList("index.query.default_field",
STRING_FIELD_NAME, "*", STRING_FIELD_NAME_2).build())
TEXT_FIELD_NAME, "*", KEYWORD_FIELD_NAME).build())
);
query = new MultiMatchQueryBuilder("hello")
.toQuery(context);
@ -399,15 +398,15 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(),
Settings.builder().putList("index.query.default_field", STRING_FIELD_NAME, STRING_FIELD_NAME_2 + "^5")
Settings.builder().putList("index.query.default_field", TEXT_FIELD_NAME, KEYWORD_FIELD_NAME + "^5")
.build())
);
MultiMatchQueryBuilder qb = new MultiMatchQueryBuilder("hello");
query = qb.toQuery(context);
DisjunctionMaxQuery expected = new DisjunctionMaxQuery(
Arrays.asList(
new TermQuery(new Term(STRING_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(STRING_FIELD_NAME_2, "hello")), 5.0f)
new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")), 5.0f)
), 0.0f
);
assertEquals(expected, query);
@ -415,7 +414,7 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(),
Settings.builder().putList("index.query.default_field",
STRING_FIELD_NAME, STRING_FIELD_NAME_2 + "^5", INT_FIELD_NAME).build())
TEXT_FIELD_NAME, KEYWORD_FIELD_NAME + "^5", INT_FIELD_NAME).build())
);
// should fail because lenient defaults to false
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> qb.toQuery(context));
@ -428,8 +427,8 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
expected = new DisjunctionMaxQuery(
Arrays.asList(
new MatchNoDocsQuery("failed [mapped_int] query, caused by number_format_exception:[For input string: \"hello\"]"),
new TermQuery(new Term(STRING_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(STRING_FIELD_NAME_2, "hello")), 5.0f)
new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")), 5.0f)
), 0.0f
);
assertEquals(expected, query);
@ -451,45 +450,45 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
assertQueryWithAllFieldsWildcard(query);
query = new MultiMatchQueryBuilder("hello")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.field("*")
.field(STRING_FIELD_NAME_2)
.field(KEYWORD_FIELD_NAME)
.toQuery(context);
assertQueryWithAllFieldsWildcard(query);
}
public void testWithStopWords() throws Exception {
Query query = new MultiMatchQueryBuilder("the quick fox")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
Query expected = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.build();
assertEquals(expected, query);
query = new MultiMatchQueryBuilder("the quick fox")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
expected = new DisjunctionMaxQuery(
Arrays.asList(
new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.build(),
new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "fox")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.build()
), 0f);
assertEquals(expected, query);
query = new MultiMatchQueryBuilder("the")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
expected = new DisjunctionMaxQuery(Arrays.asList(new MatchNoDocsQuery(), new MatchNoDocsQuery()), 0f);
@ -498,7 +497,7 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
query = new BoolQueryBuilder()
.should(
new MultiMatchQueryBuilder("the")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
)
.toQuery(createShardContext());
@ -510,8 +509,8 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
query = new BoolQueryBuilder()
.should(
new MultiMatchQueryBuilder("the")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
)
.toQuery(createShardContext());
@ -525,8 +524,8 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
public void testNegativeFieldBoost() {
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,
() -> new MultiMatchQueryBuilder("the quick fox")
.field(STRING_FIELD_NAME, -1.0f)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME, -1.0f)
.field(KEYWORD_FIELD_NAME)
.toQuery(createShardContext()));
assertThat(exc.getMessage(), containsString("negative [boost]"));
}
@ -548,8 +547,8 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
}
}
assertEquals(9, noMatchNoDocsQueries);
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(STRING_FIELD_NAME, "hello")),
new TermQuery(new Term(STRING_FIELD_NAME_2, "hello"))));
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello"))));
}
/**

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.query;
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.ScoreMode;
@ -60,7 +61,7 @@ public class NestedQueryBuilderTests extends AbstractQueryTestCase<NestedQueryBu
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc",
STRING_FIELD_NAME, "type=text",
TEXT_FIELD_NAME, "type=text",
INT_FIELD_NAME, "type=integer",
DOUBLE_FIELD_NAME, "type=double",
BOOLEAN_FIELD_NAME, "type=boolean",

View File

@ -61,8 +61,8 @@ public class PrefixQueryBuilderTests extends AbstractQueryTestCase<PrefixQueryBu
}
private static PrefixQueryBuilder randomPrefixQuery() {
String fieldName = randomFrom(STRING_FIELD_NAME,
STRING_ALIAS_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME,
TEXT_ALIAS_FIELD_NAME,
randomAlphaOfLengthBetween(1, 10));
String value = randomAlphaOfLengthBetween(1, 10);
return new PrefixQueryBuilder(fieldName, value);
@ -92,10 +92,10 @@ public class PrefixQueryBuilderTests extends AbstractQueryTestCase<PrefixQueryBu
public void testBlendedRewriteMethod() throws IOException {
String rewrite = "top_terms_blended_freqs_10";
Query parsedQuery = parseQuery(prefixQuery(STRING_FIELD_NAME, "val").rewrite(rewrite)).toQuery(createShardContext());
Query parsedQuery = parseQuery(prefixQuery(TEXT_FIELD_NAME, "val").rewrite(rewrite)).toQuery(createShardContext());
assertThat(parsedQuery, instanceOf(PrefixQuery.class));
PrefixQuery prefixQuery = (PrefixQuery) parsedQuery;
assertThat(prefixQuery.getPrefix(), equalTo(new Term(STRING_FIELD_NAME, "val")));
assertThat(prefixQuery.getPrefix(), equalTo(new Term(TEXT_FIELD_NAME, "val")));
assertThat(prefixQuery.getRewriteMethod(), instanceOf(MultiTermQuery.TopTermsBlendedFreqScoringRewrite.class));
}

View File

@ -110,19 +110,19 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
// also avoid "now" since we might hit dqte fields later and this complicates caching checks
String term = randomValueOtherThanMany(s -> s.toLowerCase(Locale.ROOT).contains("now"),
() -> randomAlphaOfLengthBetween(4, 10));
query += (randomBoolean() ? STRING_FIELD_NAME + ":" : "") + term + " ";
query += (randomBoolean() ? TEXT_FIELD_NAME + ":" : "") + term + " ";
}
QueryStringQueryBuilder queryStringQueryBuilder = new QueryStringQueryBuilder(query);
if (randomBoolean()) {
String defaultFieldName = randomFrom(STRING_FIELD_NAME,
STRING_ALIAS_FIELD_NAME,
String defaultFieldName = randomFrom(TEXT_FIELD_NAME,
TEXT_ALIAS_FIELD_NAME,
randomAlphaOfLengthBetween(1, 10));
queryStringQueryBuilder.defaultField(defaultFieldName);
} else {
int numFields = randomIntBetween(1, 5);
for (int i = 0; i < numFields; i++) {
String fieldName = randomFrom(STRING_FIELD_NAME,
STRING_ALIAS_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME,
TEXT_ALIAS_FIELD_NAME,
randomAlphaOfLengthBetween(1, 10));
if (randomBoolean()) {
queryStringQueryBuilder.field(fieldName);
@ -136,7 +136,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
}
if (randomBoolean()) {
//we only use string fields (either mapped or unmapped)
queryStringQueryBuilder.fuzziness(randomFuzziness(STRING_FIELD_NAME));
queryStringQueryBuilder.fuzziness(randomFuzziness(TEXT_FIELD_NAME));
}
if (randomBoolean()) {
queryStringQueryBuilder.analyzer(randomAnalyzer());
@ -422,34 +422,34 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
}
public void testToQueryTermQuery() throws IOException {
Query query = queryStringQuery("test").defaultField(STRING_FIELD_NAME).toQuery(createShardContext());
Query query = queryStringQuery("test").defaultField(TEXT_FIELD_NAME).toQuery(createShardContext());
assertThat(query, instanceOf(TermQuery.class));
TermQuery termQuery = (TermQuery) query;
assertThat(termQuery.getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test")));
assertThat(termQuery.getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "test")));
}
public void testToQueryPhraseQuery() throws IOException {
Query query = queryStringQuery("\"term1 term2\"")
.defaultField(STRING_FIELD_NAME)
.defaultField(TEXT_FIELD_NAME)
.phraseSlop(3)
.toQuery(createShardContext());
assertThat(query, instanceOf(PhraseQuery.class));
PhraseQuery phraseQuery = (PhraseQuery) query;
assertThat(phraseQuery.getTerms().length, equalTo(2));
assertThat(phraseQuery.getTerms()[0], equalTo(new Term(STRING_FIELD_NAME, "term1")));
assertThat(phraseQuery.getTerms()[1], equalTo(new Term(STRING_FIELD_NAME, "term2")));
assertThat(phraseQuery.getTerms()[0], equalTo(new Term(TEXT_FIELD_NAME, "term1")));
assertThat(phraseQuery.getTerms()[1], equalTo(new Term(TEXT_FIELD_NAME, "term2")));
assertThat(phraseQuery.getSlop(), equalTo(3));
}
public void testToQueryBoosts() throws Exception {
QueryShardContext shardContext = createShardContext();
QueryStringQueryBuilder queryStringQuery = queryStringQuery(STRING_FIELD_NAME + ":boosted^2");
QueryStringQueryBuilder queryStringQuery = queryStringQuery(TEXT_FIELD_NAME + ":boosted^2");
Query query = queryStringQuery.toQuery(shardContext);
assertThat(query, instanceOf(BoostQuery.class));
BoostQuery boostQuery = (BoostQuery) query;
assertThat(boostQuery.getBoost(), equalTo(2.0f));
assertThat(boostQuery.getQuery(), instanceOf(TermQuery.class));
assertThat(((TermQuery) boostQuery.getQuery()).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "boosted")));
assertThat(((TermQuery) boostQuery.getQuery()).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "boosted")));
queryStringQuery.boost(2.0f);
query = queryStringQuery.toQuery(shardContext);
assertThat(query, instanceOf(BoostQuery.class));
@ -460,7 +460,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
assertThat(boostQuery.getBoost(), equalTo(2.0f));
queryStringQuery =
queryStringQuery("((" + STRING_FIELD_NAME + ":boosted^2) AND (" + STRING_FIELD_NAME + ":foo^1.5))^3");
queryStringQuery("((" + TEXT_FIELD_NAME + ":boosted^2) AND (" + TEXT_FIELD_NAME + ":foo^1.5))^3");
query = queryStringQuery.toQuery(shardContext);
assertThat(query, instanceOf(BoostQuery.class));
boostQuery = (BoostQuery) query;
@ -468,11 +468,11 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
BoostQuery boostQuery1 = assertBooleanSubQuery(boostQuery.getQuery(), BoostQuery.class, 0);
assertThat(boostQuery1.getBoost(), equalTo(2.0f));
assertThat(boostQuery1.getQuery(), instanceOf(TermQuery.class));
assertThat(((TermQuery)boostQuery1.getQuery()).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "boosted")));
assertThat(((TermQuery)boostQuery1.getQuery()).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "boosted")));
BoostQuery boostQuery2 = assertBooleanSubQuery(boostQuery.getQuery(), BoostQuery.class, 1);
assertThat(boostQuery2.getBoost(), equalTo(1.5f));
assertThat(boostQuery2.getQuery(), instanceOf(TermQuery.class));
assertThat(((TermQuery)boostQuery2.getQuery()).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "foo")));
assertThat(((TermQuery)boostQuery2.getQuery()).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "foo")));
queryStringQuery.boost(2.0f);
query = queryStringQuery.toQuery(shardContext);
assertThat(query, instanceOf(BoostQuery.class));
@ -481,38 +481,38 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
}
public void testToQueryMultipleTermsBooleanQuery() throws Exception {
Query query = queryStringQuery("test1 test2").field(STRING_FIELD_NAME)
Query query = queryStringQuery("test1 test2").field(TEXT_FIELD_NAME)
.toQuery(createShardContext());
assertThat(query, instanceOf(BooleanQuery.class));
BooleanQuery bQuery = (BooleanQuery) query;
assertThat(bQuery.clauses().size(), equalTo(2));
assertThat(assertBooleanSubQuery(query, TermQuery.class, 0).getTerm(),
equalTo(new Term(STRING_FIELD_NAME, "test1")));
equalTo(new Term(TEXT_FIELD_NAME, "test1")));
assertThat(assertBooleanSubQuery(query, TermQuery.class, 1).getTerm(),
equalTo(new Term(STRING_FIELD_NAME, "test2")));
equalTo(new Term(TEXT_FIELD_NAME, "test2")));
}
public void testToQueryMultipleFieldsBooleanQuery() throws Exception {
Query query = queryStringQuery("test").field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
Query query = queryStringQuery("test").field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.toQuery(createShardContext());
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
DisjunctionMaxQuery bQuery = (DisjunctionMaxQuery) query;
assertThat(bQuery.getDisjuncts().size(), equalTo(2));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 0).getTerm(),
equalTo(new Term(STRING_FIELD_NAME, "test")));
equalTo(new Term(TEXT_FIELD_NAME, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 1).getTerm(),
equalTo(new Term(STRING_FIELD_NAME_2, "test")));
equalTo(new Term(KEYWORD_FIELD_NAME, "test")));
}
public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
Query query = queryStringQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2)
Query query = queryStringQuery("test").field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME)
.toQuery(createShardContext());
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) query;
List<Query> disjuncts = disMaxQuery.getDisjuncts();
assertThat(((TermQuery) disjuncts.get(0)).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test")));
assertThat(((TermQuery) disjuncts.get(1)).getTerm(), equalTo(new Term(STRING_FIELD_NAME_2, "test")));
assertThat(((TermQuery) disjuncts.get(0)).getTerm(), equalTo(new Term(TEXT_FIELD_NAME, "test")));
assertThat(((TermQuery) disjuncts.get(1)).getTerm(), equalTo(new Term(KEYWORD_FIELD_NAME, "test")));
}
public void testToQueryFieldsWildcard() throws Exception {
@ -521,39 +521,39 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
assertThat(dQuery.getDisjuncts().size(), equalTo(2));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 0).getTerm(),
equalTo(new Term(STRING_FIELD_NAME, "test")));
equalTo(new Term(TEXT_FIELD_NAME, "test")));
assertThat(assertDisjunctionSubQuery(query, TermQuery.class, 1).getTerm(),
equalTo(new Term(STRING_FIELD_NAME_2, "test")));
equalTo(new Term(KEYWORD_FIELD_NAME, "test")));
}
public void testToQueryDisMaxQuery() throws Exception {
Query query = queryStringQuery("test").field(STRING_FIELD_NAME, 2.2f)
.field(STRING_FIELD_NAME_2)
Query query = queryStringQuery("test").field(TEXT_FIELD_NAME, 2.2f)
.field(KEYWORD_FIELD_NAME)
.toQuery(createShardContext());
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) query;
List<Query> disjuncts = disMaxQuery.getDisjuncts();
assertTermOrBoostQuery(disjuncts.get(0), STRING_FIELD_NAME, "test", 2.2f);
assertTermOrBoostQuery(disjuncts.get(1), STRING_FIELD_NAME_2, "test", 1.0f);
assertTermOrBoostQuery(disjuncts.get(0), TEXT_FIELD_NAME, "test", 2.2f);
assertTermOrBoostQuery(disjuncts.get(1), KEYWORD_FIELD_NAME, "test", 1.0f);
}
public void testToQueryWildcardQuery() throws Exception {
for (Operator op : Operator.values()) {
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), STRING_FIELD_NAME);
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), TEXT_FIELD_NAME);
queryParser.setAnalyzeWildcard(true);
queryParser.setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
queryParser.setDefaultOperator(op.toQueryParserOperator());
Query query = queryParser.parse("first foo-bar-foobar* last");
Query expectedQuery =
new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "first")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "first")), defaultOp))
.add(new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanClause(new PrefixQuery(new Term(TEXT_FIELD_NAME, "foobar")), defaultOp))
.build(), defaultOp)
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "last")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "last")), defaultOp))
.build();
assertThat(query, Matchers.equalTo(expectedQuery));
}
@ -577,7 +577,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testToQueryWilcardQueryWithSynonyms() throws Exception {
for (Operator op : Operator.values()) {
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), STRING_FIELD_NAME);
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), TEXT_FIELD_NAME);
queryParser.setAnalyzeWildcard(true);
queryParser.setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
queryParser.setDefaultOperator(op.toQueryParserOperator());
@ -585,22 +585,22 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
Query query = queryParser.parse("first foo-bar-foobar* last");
Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "first"),
new Term(STRING_FIELD_NAME, "first")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "first"),
new Term(TEXT_FIELD_NAME, "first")), defaultOp))
.add(new BooleanQuery.Builder()
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "foo"),
new Term(STRING_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "bar"),
new Term(STRING_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "foo"),
new Term(TEXT_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "bar"),
new Term(TEXT_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanQuery.Builder()
.add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")),
.add(new BooleanClause(new PrefixQuery(new Term(TEXT_FIELD_NAME, "foobar")),
BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")),
.add(new BooleanClause(new PrefixQuery(new Term(TEXT_FIELD_NAME, "foobar")),
BooleanClause.Occur.SHOULD))
.build(), defaultOp)
.build(), defaultOp)
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "last"),
new Term(STRING_FIELD_NAME, "last")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "last"),
new Term(TEXT_FIELD_NAME, "last")), defaultOp))
.build();
assertThat(query, Matchers.equalTo(expectedQuery));
}
@ -609,7 +609,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testToQueryWithGraph() throws Exception {
for (Operator op : Operator.values()) {
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), STRING_FIELD_NAME);
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), TEXT_FIELD_NAME);
queryParser.setAnalyzeWildcard(true);
queryParser.setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
queryParser.setDefaultOperator(op.toQueryParserOperator());
@ -623,10 +623,10 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
Query query = queryParser.parse("guinea pig");
Query guineaPig = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "guinea")), Occur.MUST)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "pig")), Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "guinea")), Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "pig")), Occur.MUST)
.build();
TermQuery cavy = new TermQuery(new Term(STRING_FIELD_NAME, "cavy"));
TermQuery cavy = new TermQuery(new Term(TEXT_FIELD_NAME, "cavy"));
Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
@ -642,10 +642,10 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
expectedQuery = new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "guinea"))
.add(new Term(STRING_FIELD_NAME, "pig"))
.add(new Term(TEXT_FIELD_NAME, "guinea"))
.add(new Term(TEXT_FIELD_NAME, "pig"))
.build(), Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "cavy")), Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "cavy")), Occur.SHOULD)
.build(), defaultOp)
.build();
assertThat(query, Matchers.equalTo(expectedQuery));
@ -654,25 +654,25 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
// simple with additional tokens
query = queryParser.parse("that guinea pig smells");
expectedQuery = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "that")), defaultOp)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "that")), defaultOp)
.add(new BooleanQuery.Builder()
.add(guineaPig, Occur.SHOULD)
.add(cavy, Occur.SHOULD).build(), defaultOp)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "smells")), defaultOp)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "smells")), defaultOp)
.build();
assertThat(query, Matchers.equalTo(expectedQuery));
// complex
query = queryParser.parse("+that -(guinea pig) +smells");
expectedQuery = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "that")), Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "that")), Occur.MUST)
.add(new BooleanQuery.Builder()
.add(new BooleanQuery.Builder()
.add(guineaPig, Occur.SHOULD)
.add(cavy, Occur.SHOULD)
.build(), defaultOp)
.build(), Occur.MUST_NOT)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "smells")), Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "smells")), Occur.MUST)
.build();
assertThat(query, Matchers.equalTo(expectedQuery));
@ -680,10 +680,10 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
// no parent should cause guinea and pig to be treated as separate tokens
query = queryParser.parse("+that -guinea pig +smells");
expectedQuery = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "that")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "guinea")), BooleanClause.Occur.MUST_NOT)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "pig")), defaultOp)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "smells")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "that")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "guinea")), BooleanClause.Occur.MUST_NOT)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "pig")), defaultOp)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "smells")), BooleanClause.Occur.MUST)
.build();
assertThat(query, Matchers.equalTo(expectedQuery));
@ -691,31 +691,31 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
// span query
query = queryParser.parse("\"that guinea pig smells\"");
expectedQuery = new SpanNearQuery.Builder(STRING_FIELD_NAME, true)
.addClause(new SpanTermQuery(new Term(STRING_FIELD_NAME, "that")))
expectedQuery = new SpanNearQuery.Builder(TEXT_FIELD_NAME, true)
.addClause(new SpanTermQuery(new Term(TEXT_FIELD_NAME, "that")))
.addClause(
new SpanOrQuery(
new SpanNearQuery.Builder(STRING_FIELD_NAME, true)
.addClause(new SpanTermQuery(new Term(STRING_FIELD_NAME, "guinea")))
.addClause(new SpanTermQuery(new Term(STRING_FIELD_NAME, "pig"))).build(),
new SpanTermQuery(new Term(STRING_FIELD_NAME, "cavy"))))
.addClause(new SpanTermQuery(new Term(STRING_FIELD_NAME, "smells")))
new SpanNearQuery.Builder(TEXT_FIELD_NAME, true)
.addClause(new SpanTermQuery(new Term(TEXT_FIELD_NAME, "guinea")))
.addClause(new SpanTermQuery(new Term(TEXT_FIELD_NAME, "pig"))).build(),
new SpanTermQuery(new Term(TEXT_FIELD_NAME, "cavy"))))
.addClause(new SpanTermQuery(new Term(TEXT_FIELD_NAME, "smells")))
.build();
assertThat(query, Matchers.equalTo(expectedQuery));
// span query with slop
query = queryParser.parse("\"that guinea pig smells\"~2");
PhraseQuery pq1 = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "that"))
.add(new Term(STRING_FIELD_NAME, "guinea"))
.add(new Term(STRING_FIELD_NAME, "pig"))
.add(new Term(STRING_FIELD_NAME, "smells"))
.add(new Term(TEXT_FIELD_NAME, "that"))
.add(new Term(TEXT_FIELD_NAME, "guinea"))
.add(new Term(TEXT_FIELD_NAME, "pig"))
.add(new Term(TEXT_FIELD_NAME, "smells"))
.setSlop(2)
.build();
PhraseQuery pq2 = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "that"))
.add(new Term(STRING_FIELD_NAME, "cavy"))
.add(new Term(STRING_FIELD_NAME, "smells"))
.add(new Term(TEXT_FIELD_NAME, "that"))
.add(new Term(TEXT_FIELD_NAME, "cavy"))
.add(new Term(TEXT_FIELD_NAME, "smells"))
.setSlop(2)
.build();
expectedQuery = new BooleanQuery.Builder()
@ -727,7 +727,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
}
public void testToQueryRegExpQuery() throws Exception {
Query query = queryStringQuery("/foo*bar/").defaultField(STRING_FIELD_NAME)
Query query = queryStringQuery("/foo*bar/").defaultField(TEXT_FIELD_NAME)
.maxDeterminizedStates(5000)
.toQuery(createShardContext());
assertThat(query, instanceOf(RegexpQuery.class));
@ -736,7 +736,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
}
public void testToQueryRegExpQueryTooComplex() throws Exception {
QueryStringQueryBuilder queryBuilder = queryStringQuery("/[ac]*a[ac]{50,200}/").defaultField(STRING_FIELD_NAME);
QueryStringQueryBuilder queryBuilder = queryStringQuery("/[ac]*a[ac]{50,200}/").defaultField(TEXT_FIELD_NAME);
TooComplexToDeterminizeException e = expectThrows(TooComplexToDeterminizeException.class,
() -> queryBuilder.toQuery(createShardContext()));
@ -752,7 +752,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
builder.startObject(); {
builder.startObject("query_string"); {
builder.field("query", "/[ac]*a[ac]{1,10}/");
builder.field("default_field", STRING_FIELD_NAME);
builder.field("default_field", TEXT_FIELD_NAME);
builder.field("max_determinized_states", 10);
}
builder.endObject();
@ -791,7 +791,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
String queryString = new String(bytes);
for (int j = 0; j < 2; j++) {
Query query = queryStringQuery(queryString + (j == 0 ? "~" : "~auto"))
.defaultField(STRING_FIELD_NAME)
.defaultField(TEXT_FIELD_NAME)
.fuzziness(Fuzziness.AUTO)
.toQuery(createShardContext());
assertThat(query, instanceOf(FuzzyQuery.class));
@ -870,7 +870,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
float mainBoost = 2.0f / randomIntBetween(3, 20);
boosts[boosts.length - 1] = mainBoost;
QueryStringQueryBuilder queryStringQueryBuilder =
new QueryStringQueryBuilder(queryString).field(STRING_FIELD_NAME)
new QueryStringQueryBuilder(queryString).field(TEXT_FIELD_NAME)
.minimumShouldMatch("2").boost(mainBoost);
Query query = queryStringQueryBuilder.toQuery(createShardContext());
@ -886,15 +886,15 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
assertThat(booleanQuery.getMinimumNumberShouldMatch(), equalTo(2));
assertThat(booleanQuery.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.SHOULD));
assertThat(booleanQuery.clauses().get(0).getQuery(),
equalTo(new TermQuery(new Term(STRING_FIELD_NAME, "foo"))));
equalTo(new TermQuery(new Term(TEXT_FIELD_NAME, "foo"))));
assertThat(booleanQuery.clauses().get(1).getOccur(), equalTo(BooleanClause.Occur.SHOULD));
assertThat(booleanQuery.clauses().get(1).getQuery(),
equalTo(new TermQuery(new Term(STRING_FIELD_NAME, "bar"))));
equalTo(new TermQuery(new Term(TEXT_FIELD_NAME, "bar"))));
}
public void testToQueryPhraseQueryBoostAndSlop() throws IOException {
QueryStringQueryBuilder queryStringQueryBuilder =
new QueryStringQueryBuilder("\"test phrase\"~2").field(STRING_FIELD_NAME, 5f);
new QueryStringQueryBuilder("\"test phrase\"~2").field(TEXT_FIELD_NAME, 5f);
Query query = queryStringQueryBuilder.toQuery(createShardContext());
assertThat(query, instanceOf(BoostQuery.class));
BoostQuery boostQuery = (BoostQuery) query;
@ -914,10 +914,10 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
assertThat(expectedQuery, equalTo(query));
queryStringQueryBuilder =
new QueryStringQueryBuilder(STRING_FIELD_NAME + ":foo bar").field("invalid*");
new QueryStringQueryBuilder(TEXT_FIELD_NAME + ":foo bar").field("invalid*");
query = queryStringQueryBuilder.toQuery(createShardContext());
expectedQuery = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "foo")), Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "foo")), Occur.SHOULD)
.add(new MatchNoDocsQuery("empty fields"), Occur.SHOULD)
.build();
assertThat(expectedQuery, equalTo(query));
@ -927,16 +927,16 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
{
QueryStringQueryBuilder queryBuilder =
new QueryStringQueryBuilder("foo bar")
.field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2);
.field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME);
Query query = queryBuilder.toQuery(createShardContext());
BooleanQuery bq1 =
new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "foo")), BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "foo")), BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), BooleanClause.Occur.SHOULD))
.build();
List<Query> disjuncts = new ArrayList<>();
disjuncts.add(bq1);
disjuncts.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "foo bar")));
disjuncts.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "foo bar")));
DisjunctionMaxQuery expectedQuery = new DisjunctionMaxQuery(disjuncts, 0.0f);
assertThat(query, equalTo(expectedQuery));
}
@ -945,17 +945,17 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
{
QueryStringQueryBuilder queryBuilder =
new QueryStringQueryBuilder("foo bar")
.field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2);
.field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME);
queryBuilder.type(MultiMatchQueryBuilder.Type.PHRASE);
Query query = queryBuilder.toQuery(createShardContext());
List<Query> disjuncts = new ArrayList<>();
PhraseQuery pq = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "foo"))
.add(new Term(STRING_FIELD_NAME, "bar"))
.add(new Term(TEXT_FIELD_NAME, "foo"))
.add(new Term(TEXT_FIELD_NAME, "bar"))
.build();
disjuncts.add(pq);
disjuncts.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "foo bar")));
disjuncts.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "foo bar")));
DisjunctionMaxQuery expectedQuery = new DisjunctionMaxQuery(disjuncts, 0.0f);
assertThat(query, equalTo(expectedQuery));
}
@ -963,21 +963,21 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
{
QueryStringQueryBuilder queryBuilder =
new QueryStringQueryBuilder("mapped_string:other foo bar")
.field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2);
.field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME);
Query query = queryBuilder.toQuery(createShardContext());
BooleanQuery bq1 =
new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "foo")), BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "foo")), BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), BooleanClause.Occur.SHOULD))
.build();
List<Query> disjuncts = new ArrayList<>();
disjuncts.add(bq1);
disjuncts.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "foo bar")));
disjuncts.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "foo bar")));
DisjunctionMaxQuery disjunctionMaxQuery = new DisjunctionMaxQuery(disjuncts, 0.0f);
BooleanQuery expectedQuery =
new BooleanQuery.Builder()
.add(disjunctionMaxQuery, BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "other")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "other")), BooleanClause.Occur.SHOULD)
.build();
assertThat(query, equalTo(expectedQuery));
}
@ -985,17 +985,17 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
{
QueryStringQueryBuilder queryBuilder =
new QueryStringQueryBuilder("foo OR bar")
.field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2);
.field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME);
Query query = queryBuilder.toQuery(createShardContext());
List<Query> disjuncts1 = new ArrayList<>();
disjuncts1.add(new TermQuery(new Term(STRING_FIELD_NAME, "foo")));
disjuncts1.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "foo")));
disjuncts1.add(new TermQuery(new Term(TEXT_FIELD_NAME, "foo")));
disjuncts1.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "foo")));
DisjunctionMaxQuery maxQuery1 = new DisjunctionMaxQuery(disjuncts1, 0.0f);
List<Query> disjuncts2 = new ArrayList<>();
disjuncts2.add(new TermQuery(new Term(STRING_FIELD_NAME, "bar")));
disjuncts2.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "bar")));
disjuncts2.add(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")));
disjuncts2.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "bar")));
DisjunctionMaxQuery maxQuery2 = new DisjunctionMaxQuery(disjuncts2, 0.0f);
BooleanQuery expectedQuery =
@ -1020,24 +1020,24 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testExistsFieldQuery() throws Exception {
QueryShardContext context = createShardContext();
QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder(STRING_FIELD_NAME + ":*");
QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder(TEXT_FIELD_NAME + ":*");
Query query = queryBuilder.toQuery(context);
if (context.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
&& (context.fieldMapper(STRING_FIELD_NAME).omitNorms() == false)) {
assertThat(query, equalTo(new ConstantScoreQuery(new NormsFieldExistsQuery(STRING_FIELD_NAME))));
&& (context.fieldMapper(TEXT_FIELD_NAME).omitNorms() == false)) {
assertThat(query, equalTo(new ConstantScoreQuery(new NormsFieldExistsQuery(TEXT_FIELD_NAME))));
} else {
assertThat(query, equalTo(new ConstantScoreQuery(new TermQuery(new Term("_field_names", STRING_FIELD_NAME)))));
assertThat(query, equalTo(new ConstantScoreQuery(new TermQuery(new Term("_field_names", TEXT_FIELD_NAME)))));
}
for (boolean quoted : new boolean[] {true, false}) {
String value = (quoted ? "\"" : "") + STRING_FIELD_NAME + (quoted ? "\"" : "");
String value = (quoted ? "\"" : "") + TEXT_FIELD_NAME + (quoted ? "\"" : "");
queryBuilder = new QueryStringQueryBuilder("_exists_:" + value);
query = queryBuilder.toQuery(context);
if (context.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
&& (context.fieldMapper(STRING_FIELD_NAME).omitNorms() == false)) {
assertThat(query, equalTo(new ConstantScoreQuery(new NormsFieldExistsQuery(STRING_FIELD_NAME))));
&& (context.fieldMapper(TEXT_FIELD_NAME).omitNorms() == false)) {
assertThat(query, equalTo(new ConstantScoreQuery(new NormsFieldExistsQuery(TEXT_FIELD_NAME))));
} else {
assertThat(query, equalTo(new ConstantScoreQuery(new TermQuery(new Term("_field_names", STRING_FIELD_NAME)))));
assertThat(query, equalTo(new ConstantScoreQuery(new TermQuery(new Term("_field_names", TEXT_FIELD_NAME)))));
}
}
QueryShardContext contextNoType = createShardContextWithNoType();
@ -1119,53 +1119,53 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testExpandedTerms() throws Exception {
// Prefix
Query query = new QueryStringQueryBuilder("aBc*")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("whitespace")
.toQuery(createShardContext());
assertEquals(new PrefixQuery(new Term(STRING_FIELD_NAME, "aBc")), query);
assertEquals(new PrefixQuery(new Term(TEXT_FIELD_NAME, "aBc")), query);
query = new QueryStringQueryBuilder("aBc*")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("standard")
.toQuery(createShardContext());
assertEquals(new PrefixQuery(new Term(STRING_FIELD_NAME, "abc")), query);
assertEquals(new PrefixQuery(new Term(TEXT_FIELD_NAME, "abc")), query);
// Wildcard
query = new QueryStringQueryBuilder("aBc*D")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("whitespace")
.toQuery(createShardContext());
assertEquals(new WildcardQuery(new Term(STRING_FIELD_NAME, "aBc*D")), query);
assertEquals(new WildcardQuery(new Term(TEXT_FIELD_NAME, "aBc*D")), query);
query = new QueryStringQueryBuilder("aBc*D")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("standard")
.toQuery(createShardContext());
assertEquals(new WildcardQuery(new Term(STRING_FIELD_NAME, "abc*d")), query);
assertEquals(new WildcardQuery(new Term(TEXT_FIELD_NAME, "abc*d")), query);
// Fuzzy
query = new QueryStringQueryBuilder("aBc~1")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("whitespace")
.toQuery(createShardContext());
FuzzyQuery fuzzyQuery = (FuzzyQuery) query;
assertEquals(new Term(STRING_FIELD_NAME, "aBc"), fuzzyQuery.getTerm());
assertEquals(new Term(TEXT_FIELD_NAME, "aBc"), fuzzyQuery.getTerm());
query = new QueryStringQueryBuilder("aBc~1")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("standard")
.toQuery(createShardContext());
fuzzyQuery = (FuzzyQuery) query;
assertEquals(new Term(STRING_FIELD_NAME, "abc"), fuzzyQuery.getTerm());
assertEquals(new Term(TEXT_FIELD_NAME, "abc"), fuzzyQuery.getTerm());
// Range
query = new QueryStringQueryBuilder("[aBc TO BcD]")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("whitespace")
.toQuery(createShardContext());
assertEquals(new TermRangeQuery(STRING_FIELD_NAME, new BytesRef("aBc"), new BytesRef("BcD"), true, true), query);
assertEquals(new TermRangeQuery(TEXT_FIELD_NAME, new BytesRef("aBc"), new BytesRef("BcD"), true, true), query);
query = new QueryStringQueryBuilder("[aBc TO BcD]")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("standard")
.toQuery(createShardContext());
assertEquals(new TermRangeQuery(STRING_FIELD_NAME, new BytesRef("abc"), new BytesRef("bcd"), true, true), query);
assertEquals(new TermRangeQuery(TEXT_FIELD_NAME, new BytesRef("abc"), new BytesRef("bcd"), true, true), query);
}
public void testDefaultFieldsWithFields() throws IOException {
@ -1225,13 +1225,13 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
// Multi block
query = new QueryStringQueryBuilder("first unmapped:second")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.field("unmapped")
.field("another_unmapped")
.defaultOperator(Operator.AND)
.toQuery(createShardContext());
BooleanQuery expected = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "first")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "first")), BooleanClause.Occur.MUST)
.add(new MatchNoDocsQuery(), BooleanClause.Occur.MUST)
.build();
assertEquals(expected, query);
@ -1260,7 +1260,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
// `*` is in the list of the default_field => leniency set to true
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(), Settings.builder().putList("index.query.default_field",
STRING_FIELD_NAME, "*", STRING_FIELD_NAME_2).build())
TEXT_FIELD_NAME, "*", KEYWORD_FIELD_NAME).build())
);
query = new QueryStringQueryBuilder("hello")
.toQuery(context);
@ -1269,14 +1269,14 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(), Settings.builder().putList("index.query.default_field",
STRING_FIELD_NAME, STRING_FIELD_NAME_2 + "^5").build())
TEXT_FIELD_NAME, KEYWORD_FIELD_NAME + "^5").build())
);
query = new QueryStringQueryBuilder("hello")
.toQuery(context);
Query expected = new DisjunctionMaxQuery(
Arrays.asList(
new TermQuery(new Term(STRING_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(STRING_FIELD_NAME_2, "hello")), 5.0f)
new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")), 5.0f)
), 0.0f
);
assertEquals(expected, query);
@ -1297,9 +1297,9 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
assertQueryWithAllFieldsWildcard(query);
query = new QueryStringQueryBuilder("hello")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.field("*")
.field(STRING_FIELD_NAME_2)
.field(KEYWORD_FIELD_NAME)
.toQuery(context);
assertQueryWithAllFieldsWildcard(query);
}
@ -1310,16 +1310,16 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testQuoteAnalyzer() throws Exception {
// Prefix
Query query = new QueryStringQueryBuilder("ONE \"TWO THREE\"")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("whitespace")
.quoteAnalyzer("simple")
.toQuery(createShardContext());
Query expectedQuery =
new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "ONE")), Occur.SHOULD))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "ONE")), Occur.SHOULD))
.add(new BooleanClause(new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "two"), 0)
.add(new Term(STRING_FIELD_NAME, "three"), 1)
.add(new Term(TEXT_FIELD_NAME, "two"), 0)
.add(new Term(TEXT_FIELD_NAME, "three"), 1)
.build(), Occur.SHOULD))
.build();
assertEquals(expectedQuery, query);
@ -1327,77 +1327,77 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testQuoteFieldSuffix() throws IOException {
QueryShardContext context = createShardContext();
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")),
new QueryStringQueryBuilder("bar")
.quoteFieldSuffix("_2")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.doToQuery(context)
);
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME_2, "bar")),
assertEquals(new TermQuery(new Term(KEYWORD_FIELD_NAME, "bar")),
new QueryStringQueryBuilder("\"bar\"")
.quoteFieldSuffix("_2")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.doToQuery(context)
);
// Now check what happens if the quote field does not exist
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")),
new QueryStringQueryBuilder("bar")
.quoteFieldSuffix(".quote")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.doToQuery(context)
);
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")),
new QueryStringQueryBuilder("\"bar\"")
.quoteFieldSuffix(".quote")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.doToQuery(context)
);
}
public void testToFuzzyQuery() throws Exception {
Query query = new QueryStringQueryBuilder("text~2")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.fuzzyPrefixLength(2)
.fuzzyMaxExpansions(5)
.fuzzyTranspositions(false)
.toQuery(createShardContext());
FuzzyQuery expected = new FuzzyQuery(new Term(STRING_FIELD_NAME, "text"), 2, 2, 5, false);
FuzzyQuery expected = new FuzzyQuery(new Term(TEXT_FIELD_NAME, "text"), 2, 2, 5, false);
assertEquals(expected, query);
}
public void testWithStopWords() throws Exception {
Query query = new QueryStringQueryBuilder("the quick fox")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
Query expected = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.build();
assertEquals(expected, query);
query = new QueryStringQueryBuilder("the quick fox")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
expected = new DisjunctionMaxQuery(
Arrays.asList(
new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "quick")), Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "fox")), Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), Occur.SHOULD)
.build(),
new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "quick")), Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME_2, "fox")), Occur.SHOULD)
.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "quick")), Occur.SHOULD)
.add(new TermQuery(new Term(KEYWORD_FIELD_NAME, "fox")), Occur.SHOULD)
.build()
), 0f);
assertEquals(expected, query);
query = new QueryStringQueryBuilder("the")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
assertEquals(new BooleanQuery.Builder().build(), query);
@ -1405,7 +1405,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
query = new BoolQueryBuilder()
.should(
new QueryStringQueryBuilder("the")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
)
.toQuery(createShardContext());
@ -1417,8 +1417,8 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
query = new BoolQueryBuilder()
.should(
new QueryStringQueryBuilder("the")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
)
.toQuery(createShardContext());
@ -1427,26 +1427,26 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testEnablePositionIncrement() throws Exception {
Query query = new QueryStringQueryBuilder("\"quick the fox\"")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
.enablePositionIncrements(false)
.toQuery(createShardContext());
PhraseQuery expected = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "quick"))
.add(new Term(STRING_FIELD_NAME, "fox"))
.add(new Term(TEXT_FIELD_NAME, "quick"))
.add(new Term(TEXT_FIELD_NAME, "fox"))
.build();
assertEquals(expected, query);
}
public void testWithPrefixStopWords() throws Exception {
Query query = new QueryStringQueryBuilder("the* quick fox")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
BooleanQuery expected = new BooleanQuery.Builder()
.add(new PrefixQuery(new Term(STRING_FIELD_NAME, "the")), Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "quick")), Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "fox")), Occur.SHOULD)
.add(new PrefixQuery(new Term(TEXT_FIELD_NAME, "the")), Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), Occur.SHOULD)
.build();
assertEquals(expected, query);
}
@ -1456,12 +1456,12 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(),
Settings.builder().putList("index.query.default_field",
STRING_FIELD_NAME, STRING_FIELD_NAME_2).build())
TEXT_FIELD_NAME, KEYWORD_FIELD_NAME).build())
);
try {
Term[] blendedTerms = new Term[2];
blendedTerms[0] = new Term(STRING_FIELD_NAME, "foo");
blendedTerms[1] = new Term(STRING_FIELD_NAME_2, "foo");
blendedTerms[0] = new Term(TEXT_FIELD_NAME, "foo");
blendedTerms[1] = new Term(KEYWORD_FIELD_NAME, "foo");
Query query = new QueryStringQueryBuilder("foo")
.analyzer("whitespace")
@ -1476,7 +1476,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
.toQuery(createShardContext());
expected = new BooleanQuery.Builder()
.add(BlendedTermQuery.dismaxBlendedQuery(blendedTerms, 1.0f), Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "10")), Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "10")), Occur.SHOULD)
.build();
assertEquals(expected, query);
} finally {
@ -1491,37 +1491,37 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testPhraseSlop() throws Exception {
Query query = new QueryStringQueryBuilder("quick fox")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.type(MultiMatchQueryBuilder.Type.PHRASE)
.toQuery(createShardContext());
PhraseQuery expected = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "quick"))
.add(new Term(STRING_FIELD_NAME, "fox"))
.add(new Term(TEXT_FIELD_NAME, "quick"))
.add(new Term(TEXT_FIELD_NAME, "fox"))
.build();
assertEquals(expected, query);
query = new QueryStringQueryBuilder("quick fox")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.type(MultiMatchQueryBuilder.Type.PHRASE)
.phraseSlop(2)
.toQuery(createShardContext());
expected = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "quick"))
.add(new Term(STRING_FIELD_NAME, "fox"))
.add(new Term(TEXT_FIELD_NAME, "quick"))
.add(new Term(TEXT_FIELD_NAME, "fox"))
.setSlop(2)
.build();
assertEquals(expected, query);
query = new QueryStringQueryBuilder("\"quick fox\"")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.phraseSlop(2)
.toQuery(createShardContext());
assertEquals(expected, query);
query = new QueryStringQueryBuilder("\"quick fox\"~2")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.phraseSlop(10)
.toQuery(createShardContext());
assertEquals(expected, query);
@ -1529,19 +1529,19 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testAnalyzedPrefix() throws Exception {
Query query = new QueryStringQueryBuilder("quick* @&*")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("standard")
.analyzeWildcard(true)
.toQuery(createShardContext());
Query expected = new PrefixQuery(new Term(STRING_FIELD_NAME, "quick"));
Query expected = new PrefixQuery(new Term(TEXT_FIELD_NAME, "quick"));
assertEquals(expected, query);
}
public void testNegativeFieldBoost() {
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,
() -> new QueryStringQueryBuilder("the quick fox")
.field(STRING_FIELD_NAME, -1.0f)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME, -1.0f)
.field(KEYWORD_FIELD_NAME)
.toQuery(createShardContext()));
assertThat(exc.getMessage(), CoreMatchers.containsString("negative [boost]"));
}
@ -1549,12 +1549,12 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
public void testMergeBoosts() throws IOException {
Query query = new QueryStringQueryBuilder("first")
.type(MultiMatchQueryBuilder.Type.MOST_FIELDS)
.field(STRING_FIELD_NAME, 0.3f)
.field(STRING_FIELD_NAME.substring(0, STRING_FIELD_NAME.length()-2) + "*", 0.5f)
.field(TEXT_FIELD_NAME, 0.3f)
.field(TEXT_FIELD_NAME.substring(0, TEXT_FIELD_NAME.length()-2) + "*", 0.5f)
.toQuery(createShardContext());
List<Query> terms = new ArrayList<>();
terms.add(new BoostQuery(new TermQuery(new Term(STRING_FIELD_NAME, "first")), 0.075f));
terms.add(new BoostQuery(new TermQuery(new Term(STRING_FIELD_NAME_2, "first")), 0.5f));
terms.add(new BoostQuery(new TermQuery(new Term(TEXT_FIELD_NAME, "first")), 0.075f));
terms.add(new BoostQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "first")), 0.5f));
Query expected = new DisjunctionMaxQuery(terms, 1.0f);
assertEquals(expected, query);
}
@ -1576,8 +1576,8 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
}
}
assertEquals(9, noMatchNoDocsQueries);
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(STRING_FIELD_NAME, "hello")),
new TermQuery(new Term(STRING_FIELD_NAME_2, "hello"))));
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello"))));
}
/**

View File

@ -25,8 +25,8 @@ import org.elasticsearch.common.Strings;
import java.util.Random;
import static org.elasticsearch.test.AbstractBuilderTestCase.STRING_ALIAS_FIELD_NAME;
import static org.elasticsearch.test.AbstractBuilderTestCase.STRING_FIELD_NAME;
import static org.elasticsearch.test.AbstractBuilderTestCase.TEXT_ALIAS_FIELD_NAME;
import static org.elasticsearch.test.AbstractBuilderTestCase.TEXT_FIELD_NAME;
import static org.elasticsearch.test.ESTestCase.randomFrom;
/**
@ -67,7 +67,7 @@ public class RandomQueryBuilder {
// for now, only use String Rangequeries for MultiTerm test, numeric and date makes little sense
// see issue #12123 for discussion
MultiTermQueryBuilder multiTermQueryBuilder;
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME);
switch(RandomNumbers.randomIntBetween(r, 0, 3)) {
case 0:
RangeQueryBuilder stringRangeQuery = new RangeQueryBuilder(fieldName);

View File

@ -93,7 +93,7 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
break;
case 2:
default:
query = new RangeQueryBuilder(randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME));
query = new RangeQueryBuilder(randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME));
query.from("a" + randomAlphaOfLengthBetween(1, 10));
query.to("z" + randomAlphaOfLengthBetween(1, 10));
break;

View File

@ -70,7 +70,7 @@ public class RegexpQueryBuilderTests extends AbstractQueryTestCase<RegexpQueryBu
private static RegexpQueryBuilder randomRegexpQuery() {
// mapped or unmapped fields
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, randomAlphaOfLengthBetween(1, 10));
String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME, randomAlphaOfLengthBetween(1, 10));
String value = randomAlphaOfLengthBetween(1, 10);
return new RegexpQueryBuilder(fieldName, value);
}

View File

@ -102,10 +102,10 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
Map<String, Float> fields = new HashMap<>();
for (int i = 0; i < fieldCount; i++) {
if (i == 0) {
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
String fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME);
fields.put(fieldName, AbstractQueryBuilder.DEFAULT_BOOST);
} else {
fields.put(STRING_FIELD_NAME_2, 2.0f / randomIntBetween(1, 20));
fields.put(KEYWORD_FIELD_NAME, 2.0f / randomIntBetween(1, 20));
}
}
@ -180,7 +180,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
// Check operator handling, and default field handling.
public void testDefaultOperatorHandling() throws IOException {
SimpleQueryStringBuilder qb = new SimpleQueryStringBuilder("The quick brown fox.").field(STRING_FIELD_NAME);
SimpleQueryStringBuilder qb = new SimpleQueryStringBuilder("The quick brown fox.").field(TEXT_FIELD_NAME);
QueryShardContext shardContext = createShardContext();
shardContext.setAllowUnmappedFields(true); // to avoid occasional cases
// in setup where we didn't
@ -319,7 +319,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
public void testToQueryBoost() throws IOException {
QueryShardContext shardContext = createShardContext();
SimpleQueryStringBuilder simpleQueryStringBuilder = new SimpleQueryStringBuilder("test");
simpleQueryStringBuilder.field(STRING_FIELD_NAME, 5);
simpleQueryStringBuilder.field(TEXT_FIELD_NAME, 5);
Query query = simpleQueryStringBuilder.toQuery(shardContext);
assertThat(query, instanceOf(BoostQuery.class));
BoostQuery boostQuery = (BoostQuery) query;
@ -327,7 +327,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
assertThat(boostQuery.getQuery(), instanceOf(TermQuery.class));
simpleQueryStringBuilder = new SimpleQueryStringBuilder("test");
simpleQueryStringBuilder.field(STRING_FIELD_NAME, 5);
simpleQueryStringBuilder.field(TEXT_FIELD_NAME, 5);
simpleQueryStringBuilder.boost(2);
query = simpleQueryStringBuilder.toQuery(shardContext);
boostQuery = (BoostQuery) query;
@ -393,7 +393,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
}
int numberOfFields = randomIntBetween(1, 4);
for (int i = 0; i < numberOfFields; i++) {
simpleQueryStringBuilder.field(STRING_FIELD_NAME);
simpleQueryStringBuilder.field(TEXT_FIELD_NAME);
}
int percent = randomIntBetween(1, 100);
simpleQueryStringBuilder.minimumShouldMatch(percent + "%");
@ -418,28 +418,28 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
public void testExpandedTerms() throws Exception {
// Prefix
Query query = new SimpleQueryStringBuilder("aBc*")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("whitespace")
.toQuery(createShardContext());
assertEquals(new PrefixQuery(new Term(STRING_FIELD_NAME, "aBc")), query);
assertEquals(new PrefixQuery(new Term(TEXT_FIELD_NAME, "aBc")), query);
query = new SimpleQueryStringBuilder("aBc*")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("standard")
.toQuery(createShardContext());
assertEquals(new PrefixQuery(new Term(STRING_FIELD_NAME, "abc")), query);
assertEquals(new PrefixQuery(new Term(TEXT_FIELD_NAME, "abc")), query);
// Fuzzy
query = new SimpleQueryStringBuilder("aBc~1")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("whitespace")
.toQuery(createShardContext());
FuzzyQuery expected = new FuzzyQuery(new Term(STRING_FIELD_NAME, "aBc"), 1);
FuzzyQuery expected = new FuzzyQuery(new Term(TEXT_FIELD_NAME, "aBc"), 1);
assertEquals(expected, query);
query = new SimpleQueryStringBuilder("aBc~1")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("standard")
.toQuery(createShardContext());
expected = new FuzzyQuery(new Term(STRING_FIELD_NAME, "abc"), 1);
expected = new FuzzyQuery(new Term(TEXT_FIELD_NAME, "abc"), 1);
assertEquals(expected, query);
}
@ -447,20 +447,20 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
SimpleQueryStringQueryParser.Settings settings = new SimpleQueryStringQueryParser.Settings();
settings.analyzeWildcard(true);
SimpleQueryStringQueryParser parser = new SimpleQueryStringQueryParser(new StandardAnalyzer(),
Collections.singletonMap(STRING_FIELD_NAME, 1.0f), -1, settings, createShardContext());
Collections.singletonMap(TEXT_FIELD_NAME, 1.0f), -1, settings, createShardContext());
for (Operator op : Operator.values()) {
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
parser.setDefaultOperator(defaultOp);
Query query = parser.parse("first foo-bar-foobar* last");
Query expectedQuery =
new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "first")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "first")), defaultOp))
.add(new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanClause(new PrefixQuery(new Term(TEXT_FIELD_NAME, "foobar")), defaultOp))
.build(), defaultOp)
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "last")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "last")), defaultOp))
.build();
assertThat(query, equalTo(expectedQuery));
}
@ -470,28 +470,28 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
SimpleQueryStringQueryParser.Settings settings = new SimpleQueryStringQueryParser.Settings();
settings.analyzeWildcard(true);
SimpleQueryStringQueryParser parser = new SimpleQueryStringQueryParser(new MockRepeatAnalyzer(),
Collections.singletonMap(STRING_FIELD_NAME, 1.0f), -1, settings, createShardContext());
Collections.singletonMap(TEXT_FIELD_NAME, 1.0f), -1, settings, createShardContext());
for (Operator op : Operator.values()) {
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
parser.setDefaultOperator(defaultOp);
Query query = parser.parse("first foo-bar-foobar* last");
Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "first"),
new Term(STRING_FIELD_NAME, "first")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "first"),
new Term(TEXT_FIELD_NAME, "first")), defaultOp))
.add(new BooleanQuery.Builder()
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "foo"),
new Term(STRING_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "bar"),
new Term(STRING_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "foo"),
new Term(TEXT_FIELD_NAME, "foo")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "bar"),
new Term(TEXT_FIELD_NAME, "bar")), defaultOp))
.add(new BooleanQuery.Builder()
.add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")),
.add(new BooleanClause(new PrefixQuery(new Term(TEXT_FIELD_NAME, "foobar")),
BooleanClause.Occur.SHOULD))
.add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")),
.add(new BooleanClause(new PrefixQuery(new Term(TEXT_FIELD_NAME, "foobar")),
BooleanClause.Occur.SHOULD))
.build(), defaultOp)
.build(), defaultOp)
.add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "last"),
new Term(STRING_FIELD_NAME, "last")), defaultOp))
.add(new BooleanClause(new SynonymQuery(new Term(TEXT_FIELD_NAME, "last"),
new Term(TEXT_FIELD_NAME, "last")), defaultOp))
.build();
assertThat(query, equalTo(expectedQuery));
}
@ -501,7 +501,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
SimpleQueryStringQueryParser.Settings settings = new SimpleQueryStringQueryParser.Settings();
settings.analyzeWildcard(true);
SimpleQueryStringQueryParser parser = new SimpleQueryStringQueryParser(new MockSynonymAnalyzer(),
Collections.singletonMap(STRING_FIELD_NAME, 1.0f), -1, settings, createShardContext());
Collections.singletonMap(TEXT_FIELD_NAME, 1.0f), -1, settings, createShardContext());
for (Operator op : Operator.values()) {
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
parser.setDefaultOperator(defaultOp);
@ -509,37 +509,37 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
Query query = parser.parse("guinea pig");
Query expectedQuery = new BooleanQuery.Builder()
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "guinea")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "pig")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "guinea")), defaultOp))
.add(new BooleanClause(new TermQuery(new Term(TEXT_FIELD_NAME, "pig")), defaultOp))
.build();
assertThat(query, equalTo(expectedQuery));
// phrase will pick it up
query = parser.parse("\"guinea pig\"");
SpanTermQuery span1 = new SpanTermQuery(new Term(STRING_FIELD_NAME, "guinea"));
SpanTermQuery span2 = new SpanTermQuery(new Term(STRING_FIELD_NAME, "pig"));
SpanTermQuery span1 = new SpanTermQuery(new Term(TEXT_FIELD_NAME, "guinea"));
SpanTermQuery span2 = new SpanTermQuery(new Term(TEXT_FIELD_NAME, "pig"));
expectedQuery = new SpanOrQuery(
new SpanNearQuery(new SpanQuery[] { span1, span2 }, 0, true),
new SpanTermQuery(new Term(STRING_FIELD_NAME, "cavy")));
new SpanTermQuery(new Term(TEXT_FIELD_NAME, "cavy")));
assertThat(query, equalTo(expectedQuery));
// phrase with slop
query = parser.parse("big \"tiny guinea pig\"~2");
PhraseQuery pq1 = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "tiny"))
.add(new Term(STRING_FIELD_NAME, "guinea"))
.add(new Term(STRING_FIELD_NAME, "pig"))
.add(new Term(TEXT_FIELD_NAME, "tiny"))
.add(new Term(TEXT_FIELD_NAME, "guinea"))
.add(new Term(TEXT_FIELD_NAME, "pig"))
.setSlop(2)
.build();
PhraseQuery pq2 = new PhraseQuery.Builder()
.add(new Term(STRING_FIELD_NAME, "tiny"))
.add(new Term(STRING_FIELD_NAME, "cavy"))
.add(new Term(TEXT_FIELD_NAME, "tiny"))
.add(new Term(TEXT_FIELD_NAME, "cavy"))
.setSlop(2)
.build();
expectedQuery = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "big")), defaultOp)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "big")), defaultOp)
.add(new BooleanQuery.Builder()
.add(pq1, BooleanClause.Occur.SHOULD)
.add(pq2, BooleanClause.Occur.SHOULD)
@ -555,16 +555,16 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
settings.analyzeWildcard(true);
settings.quoteFieldSuffix("_2");
SimpleQueryStringQueryParser parser = new SimpleQueryStringQueryParser(new MockSynonymAnalyzer(),
Collections.singletonMap(STRING_FIELD_NAME, 1.0f), -1, settings, createShardContext());
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), parser.parse("bar"));
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME_2, "bar")), parser.parse("\"bar\""));
Collections.singletonMap(TEXT_FIELD_NAME, 1.0f), -1, settings, createShardContext());
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), parser.parse("bar"));
assertEquals(new TermQuery(new Term(KEYWORD_FIELD_NAME, "bar")), parser.parse("\"bar\""));
// Now check what happens if the quote field does not exist
settings.quoteFieldSuffix(".quote");
parser = new SimpleQueryStringQueryParser(new MockSynonymAnalyzer(),
Collections.singletonMap(STRING_FIELD_NAME, 1.0f), -1, settings, createShardContext());
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), parser.parse("bar"));
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), parser.parse("\"bar\""));
Collections.singletonMap(TEXT_FIELD_NAME, 1.0f), -1, settings, createShardContext());
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), parser.parse("bar"));
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), parser.parse("\"bar\""));
}
public void testDefaultField() throws Exception {
@ -578,7 +578,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
// `*` is in the list of the default_field => leniency set to true
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(), Settings.builder().putList("index.query.default_field",
STRING_FIELD_NAME, "*", STRING_FIELD_NAME_2).build())
TEXT_FIELD_NAME, "*", KEYWORD_FIELD_NAME).build())
);
query = new SimpleQueryStringBuilder("hello")
.toQuery(context);
@ -586,14 +586,14 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
context.getIndexSettings().updateIndexMetadata(
newIndexMeta("index", context.getIndexSettings().getSettings(), Settings.builder().putList("index.query.default_field",
STRING_FIELD_NAME, STRING_FIELD_NAME_2 + "^5").build())
TEXT_FIELD_NAME, KEYWORD_FIELD_NAME + "^5").build())
);
query = new SimpleQueryStringBuilder("hello")
.toQuery(context);
Query expected = new DisjunctionMaxQuery(
Arrays.asList(
new TermQuery(new Term(STRING_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(STRING_FIELD_NAME_2, "hello")), 5.0f)
new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new BoostQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")), 5.0f)
), 1.0f
);
assertEquals(expected, query);
@ -614,70 +614,70 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
assertQueryWithAllFieldsWildcard(query);
query = new SimpleQueryStringBuilder("hello")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.field("*")
.field(STRING_FIELD_NAME_2)
.field(KEYWORD_FIELD_NAME)
.toQuery(context);
assertQueryWithAllFieldsWildcard(query);
}
public void testToFuzzyQuery() throws Exception {
Query query = new SimpleQueryStringBuilder("text~2")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.fuzzyPrefixLength(2)
.fuzzyMaxExpansions(5)
.fuzzyTranspositions(false)
.toQuery(createShardContext());
FuzzyQuery expected = new FuzzyQuery(new Term(STRING_FIELD_NAME, "text"), 2, 2, 5, false);
FuzzyQuery expected = new FuzzyQuery(new Term(TEXT_FIELD_NAME, "text"), 2, 2, 5, false);
assertEquals(expected, query);
}
public void testLenientToPrefixQuery() throws Exception {
Query query = new SimpleQueryStringBuilder("t*")
.field(DATE_FIELD_NAME)
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.lenient(true)
.toQuery(createShardContext());
List<Query> expectedQueries = new ArrayList<>();
expectedQueries.add(new MatchNoDocsQuery(""));
expectedQueries.add(new PrefixQuery(new Term(STRING_FIELD_NAME, "t")));
expectedQueries.add(new PrefixQuery(new Term(TEXT_FIELD_NAME, "t")));
DisjunctionMaxQuery expected = new DisjunctionMaxQuery(expectedQueries, 1.0f);
assertEquals(expected, query);
}
public void testWithStopWords() throws Exception {
Query query = new SimpleQueryStringBuilder("the quick fox")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
Query expected = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.build();
assertEquals(expected, query);
query = new SimpleQueryStringBuilder("the quick fox")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
expected = new BooleanQuery.Builder()
.add(new DisjunctionMaxQuery(
Arrays.asList(
new TermQuery(new Term(STRING_FIELD_NAME, "quick")),
new TermQuery(new Term(STRING_FIELD_NAME_2, "quick"))
new TermQuery(new Term(TEXT_FIELD_NAME, "quick")),
new TermQuery(new Term(KEYWORD_FIELD_NAME, "quick"))
), 1.0f), BooleanClause.Occur.SHOULD)
.add(new DisjunctionMaxQuery(
Arrays.asList(
new TermQuery(new Term(STRING_FIELD_NAME, "fox")),
new TermQuery(new Term(STRING_FIELD_NAME_2, "fox"))
new TermQuery(new Term(TEXT_FIELD_NAME, "fox")),
new TermQuery(new Term(KEYWORD_FIELD_NAME, "fox"))
), 1.0f), BooleanClause.Occur.SHOULD)
.build();
assertEquals(expected, query);
query = new SimpleQueryStringBuilder("the")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
assertEquals(new MatchNoDocsQuery(), query);
@ -685,7 +685,7 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
query = new BoolQueryBuilder()
.should(
new SimpleQueryStringBuilder("the")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
)
.toQuery(createShardContext());
@ -697,8 +697,8 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
query = new BoolQueryBuilder()
.should(
new SimpleQueryStringBuilder("the")
.field(STRING_FIELD_NAME)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME)
.field(KEYWORD_FIELD_NAME)
.analyzer("stop")
)
.toQuery(createShardContext());
@ -707,13 +707,13 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
public void testWithPrefixStopWords() throws Exception {
Query query = new SimpleQueryStringBuilder("the* quick fox")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.analyzer("stop")
.toQuery(createShardContext());
BooleanQuery expected = new BooleanQuery.Builder()
.add(new PrefixQuery(new Term(STRING_FIELD_NAME, "the")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.add(new PrefixQuery(new Term(TEXT_FIELD_NAME, "the")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.build();
assertEquals(expected, query);
}
@ -726,14 +726,14 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
*/
public void testUnmappedFieldNoTokenWithAndOperator() throws IOException {
Query query = new SimpleQueryStringBuilder("first & second")
.field(STRING_FIELD_NAME)
.field(TEXT_FIELD_NAME)
.field("unmapped")
.field("another_unmapped")
.defaultOperator(Operator.AND)
.toQuery(createShardContext());
BooleanQuery expected = new BooleanQuery.Builder()
.add(new TermQuery(new Term(STRING_FIELD_NAME, "first")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(STRING_FIELD_NAME, "second")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "first")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "second")), BooleanClause.Occur.MUST)
.build();
assertEquals(expected, query);
query = new SimpleQueryStringBuilder("first & second")
@ -752,8 +752,8 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
public void testNegativeFieldBoost() {
IllegalArgumentException exc = expectThrows(IllegalArgumentException.class,
() -> new SimpleQueryStringBuilder("the quick fox")
.field(STRING_FIELD_NAME, -1.0f)
.field(STRING_FIELD_NAME_2)
.field(TEXT_FIELD_NAME, -1.0f)
.field(KEYWORD_FIELD_NAME)
.toQuery(createShardContext()));
assertThat(exc.getMessage(), containsString("negative [boost]"));
}
@ -775,8 +775,8 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
}
}
assertEquals(9, noMatchNoDocsQueries);
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(STRING_FIELD_NAME, "hello")),
new TermQuery(new Term(STRING_FIELD_NAME_2, "hello"))));
assertThat(disjunctionMaxQuery.getDisjuncts(), hasItems(new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello"))));
}
/**

View File

@ -37,8 +37,8 @@ public class SpanTermQueryBuilderTests extends AbstractTermQueryTestCase<SpanTer
@Override
protected SpanTermQueryBuilder doCreateTestQueryBuilder() {
String fieldName = randomFrom(STRING_FIELD_NAME,
STRING_ALIAS_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME,
TEXT_ALIAS_FIELD_NAME,
randomAlphaOfLengthBetween(1, 10));
Object value;

View File

@ -49,7 +49,7 @@ public class TermQueryBuilderTests extends AbstractTermQueryTestCase<TermQueryBu
break;
case 1:
if (randomBoolean()) {
fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME);
}
if (frequently()) {
value = randomAlphaOfLengthBetween(1, 10);

View File

@ -94,7 +94,7 @@ public class TermsQueryBuilderTests extends AbstractQueryTestCase<TermsQueryBuil
query = new TermsQueryBuilder(fieldName, values);
} else {
// right now the mock service returns us a list of strings
query = new TermsQueryBuilder(randomBoolean() ? randomAlphaOfLengthBetween(1,10) : STRING_FIELD_NAME, randomTermsLookup());
query = new TermsQueryBuilder(randomBoolean() ? randomAlphaOfLengthBetween(1,10) : TEXT_FIELD_NAME, randomTermsLookup());
}
return query;
}
@ -272,7 +272,7 @@ public class TermsQueryBuilderTests extends AbstractQueryTestCase<TermsQueryBuil
@Override
public void testMustRewrite() throws IOException {
TermsQueryBuilder termsQueryBuilder = new TermsQueryBuilder(STRING_FIELD_NAME, randomTermsLookup());
TermsQueryBuilder termsQueryBuilder = new TermsQueryBuilder(TEXT_FIELD_NAME, randomTermsLookup());
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> termsQueryBuilder.toQuery(createShardContext()));
assertEquals("query must be rewritten first", e.getMessage());
@ -283,7 +283,7 @@ public class TermsQueryBuilderTests extends AbstractQueryTestCase<TermsQueryBuil
if (nonNullTerms.isEmpty()) {
expected = new MatchNoneQueryBuilder();
} else {
expected = new TermsQueryBuilder(STRING_FIELD_NAME, nonNullTerms);
expected = new TermsQueryBuilder(TEXT_FIELD_NAME, nonNullTerms);
}
assertEquals(expected, rewriteAndFetch(termsQueryBuilder, createShardContext()));
}
@ -298,7 +298,7 @@ public class TermsQueryBuilderTests extends AbstractQueryTestCase<TermsQueryBuil
}
public void testSerializationFailsUnlessFetched() throws IOException {
QueryBuilder builder = new TermsQueryBuilder(STRING_FIELD_NAME, randomTermsLookup());
QueryBuilder builder = new TermsQueryBuilder(TEXT_FIELD_NAME, randomTermsLookup());
QueryBuilder termsQueryBuilder = Rewriteable.rewrite(builder, createShardContext());
IllegalStateException ise = expectThrows(IllegalStateException.class, () -> termsQueryBuilder.writeTo(new BytesStreamOutput(10)));
assertEquals(ise.getMessage(), "supplier must be null, can't serialize suppliers, missing a rewriteAndFetch?");

View File

@ -88,7 +88,7 @@ public class TermsSetQueryBuilderTests extends AbstractQueryTestCase<TermsSetQue
value -> value.equals(GEO_POINT_FIELD_NAME) || value.equals(GEO_SHAPE_FIELD_NAME),
() -> randomFrom(MAPPED_FIELD_NAMES));
List<?> randomTerms = randomValues(fieldName);
TermsSetQueryBuilder queryBuilder = new TermsSetQueryBuilder(STRING_FIELD_NAME, randomTerms);
TermsSetQueryBuilder queryBuilder = new TermsSetQueryBuilder(TEXT_FIELD_NAME, randomTerms);
if (randomBoolean()) {
queryBuilder.setMinimumShouldMatchField("m_s_m");
} else {
@ -124,14 +124,14 @@ public class TermsSetQueryBuilderTests extends AbstractQueryTestCase<TermsSetQue
context.isCacheable());
// specifically trigger the two cases where query is cacheable
queryBuilder = new TermsSetQueryBuilder(STRING_FIELD_NAME, Collections.singletonList("foo"));
queryBuilder = new TermsSetQueryBuilder(TEXT_FIELD_NAME, Collections.singletonList("foo"));
queryBuilder.setMinimumShouldMatchField("m_s_m");
context = createShardContext();
rewriteQuery(queryBuilder, new QueryShardContext(context));
assertNotNull(queryBuilder.doToQuery(context));
assertTrue("query should be cacheable: " + queryBuilder.toString(), context.isCacheable());
queryBuilder = new TermsSetQueryBuilder(STRING_FIELD_NAME, Collections.emptyList());
queryBuilder = new TermsSetQueryBuilder(TEXT_FIELD_NAME, Collections.emptyList());
queryBuilder.setMinimumShouldMatchScript(new Script(ScriptType.INLINE, MockScriptEngine.NAME, "_script", emptyMap()));
context = createShardContext();
rewriteQuery(queryBuilder, new QueryShardContext(context));
@ -139,7 +139,7 @@ public class TermsSetQueryBuilderTests extends AbstractQueryTestCase<TermsSetQue
assertTrue("query should be cacheable: " + queryBuilder.toString(), context.isCacheable());
// also test one case where query is not cacheable
queryBuilder = new TermsSetQueryBuilder(STRING_FIELD_NAME, Collections.singletonList("foo"));
queryBuilder = new TermsSetQueryBuilder(TEXT_FIELD_NAME, Collections.singletonList("foo"));
queryBuilder.setMinimumShouldMatchScript(new Script(ScriptType.INLINE, MockScriptEngine.NAME, "_script", emptyMap()));
context = createShardContext();
rewriteQuery(queryBuilder, new QueryShardContext(context));
@ -295,7 +295,7 @@ public class TermsSetQueryBuilderTests extends AbstractQueryTestCase<TermsSetQue
public void testFieldAlias() {
List<String> randomTerms = Arrays.asList(generateRandomStringArray(5, 10, false, false));
TermsSetQueryBuilder queryBuilder = new TermsSetQueryBuilder(STRING_ALIAS_FIELD_NAME, randomTerms)
TermsSetQueryBuilder queryBuilder = new TermsSetQueryBuilder(TEXT_ALIAS_FIELD_NAME, randomTerms)
.setMinimumShouldMatchField("m_s_m");
QueryShardContext context = createShardContext();

View File

@ -58,8 +58,8 @@ public class WildcardQueryBuilderTests extends AbstractQueryTestCase<WildcardQue
}
private static WildcardQueryBuilder randomWildcardQuery() {
String fieldName = randomFrom(STRING_FIELD_NAME,
STRING_ALIAS_FIELD_NAME,
String fieldName = randomFrom(TEXT_FIELD_NAME,
TEXT_ALIAS_FIELD_NAME,
randomAlphaOfLengthBetween(1, 10));
String text = randomAlphaOfLengthBetween(1, 10);
@ -70,7 +70,7 @@ public class WildcardQueryBuilderTests extends AbstractQueryTestCase<WildcardQue
protected void doAssertLuceneQuery(WildcardQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
String expectedFieldName = expectedFieldName(queryBuilder.fieldName());
if (expectedFieldName.equals(STRING_FIELD_NAME)) {
if (expectedFieldName.equals(TEXT_FIELD_NAME)) {
assertThat(query, instanceOf(WildcardQuery.class));
WildcardQuery wildcardQuery = (WildcardQuery) query;
@ -98,7 +98,7 @@ public class WildcardQueryBuilderTests extends AbstractQueryTestCase<WildcardQue
public void testEmptyValue() throws IOException {
QueryShardContext context = createShardContext();
context.setAllowUnmappedFields(true);
WildcardQueryBuilder wildcardQueryBuilder = new WildcardQueryBuilder(STRING_FIELD_NAME, "");
WildcardQueryBuilder wildcardQueryBuilder = new WildcardQueryBuilder(TEXT_FIELD_NAME, "");
assertEquals(wildcardQueryBuilder.toQuery(context).getClass(), WildcardQuery.class);
}

View File

@ -119,7 +119,7 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase<WrapperQuery
@Override
public void testMustRewrite() throws IOException {
TermQueryBuilder tqb = new TermQueryBuilder(STRING_FIELD_NAME, "bar");
TermQueryBuilder tqb = new TermQueryBuilder(TEXT_FIELD_NAME, "bar");
WrapperQueryBuilder qb = new WrapperQueryBuilder(tqb.toString());
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class, () -> qb.toQuery(createShardContext()));
assertEquals("this query must be rewritten first", e.getMessage());
@ -137,7 +137,7 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase<WrapperQuery
}
public void testRewriteWithInnerBoost() throws IOException {
final TermQueryBuilder query = new TermQueryBuilder(STRING_FIELD_NAME, "bar").boost(2);
final TermQueryBuilder query = new TermQueryBuilder(TEXT_FIELD_NAME, "bar").boost(2);
QueryBuilder builder = new WrapperQueryBuilder(query.toString());
QueryShardContext shardContext = createShardContext();
assertEquals(query, builder.rewrite(shardContext));
@ -149,15 +149,15 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase<WrapperQuery
QueryShardContext shardContext = createShardContext();
QueryBuilder qb = new WrapperQueryBuilder(
new WrapperQueryBuilder(new TermQueryBuilder(STRING_FIELD_NAME, "bar").toString()).toString()
new WrapperQueryBuilder(new TermQueryBuilder(TEXT_FIELD_NAME, "bar").toString()).toString()
);
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), qb.rewrite(shardContext).toQuery(shardContext));
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), qb.rewrite(shardContext).toQuery(shardContext));
qb = new WrapperQueryBuilder(
new WrapperQueryBuilder(
new WrapperQueryBuilder(new TermQueryBuilder(STRING_FIELD_NAME, "bar").toString()).toString()
new WrapperQueryBuilder(new TermQueryBuilder(TEXT_FIELD_NAME, "bar").toString()).toString()
).toString()
);
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), qb.rewrite(shardContext).toQuery(shardContext));
assertEquals(new TermQuery(new Term(TEXT_FIELD_NAME, "bar")), qb.rewrite(shardContext).toQuery(shardContext));
qb = new WrapperQueryBuilder(new BoolQueryBuilder().toString());
assertEquals(new MatchAllDocsQuery(), qb.rewrite(shardContext).toQuery(shardContext));

View File

@ -553,11 +553,11 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
public void testCustomWeightFactorQueryBuilderWithFunctionScore() throws IOException {
QueryShardContext context = createShardContext();
Query parsedQuery = parseQuery(functionScoreQuery(termQuery(STRING_FIELD_NAME_2, "banon"), weightFactorFunction(1.3f)))
Query parsedQuery = parseQuery(functionScoreQuery(termQuery(KEYWORD_FIELD_NAME, "banon"), weightFactorFunction(1.3f)))
.rewrite(context).toQuery(context);
assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class));
FunctionScoreQuery functionScoreQuery = (FunctionScoreQuery) parsedQuery;
assertThat(((TermQuery) functionScoreQuery.getSubQuery()).getTerm(), equalTo(new Term(STRING_FIELD_NAME_2, "banon")));
assertThat(((TermQuery) functionScoreQuery.getSubQuery()).getTerm(), equalTo(new Term(KEYWORD_FIELD_NAME, "banon")));
assertThat((double) (functionScoreQuery.getFunctions()[0]).getWeight(), closeTo(1.3, 0.001));
}
@ -643,14 +643,14 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
public void testRewrite() throws IOException {
FunctionScoreQueryBuilder functionScoreQueryBuilder =
new FunctionScoreQueryBuilder(new WrapperQueryBuilder(new TermQueryBuilder(STRING_FIELD_NAME, "bar").toString()))
new FunctionScoreQueryBuilder(new WrapperQueryBuilder(new TermQueryBuilder(TEXT_FIELD_NAME, "bar").toString()))
.boostMode(CombineFunction.REPLACE)
.scoreMode(FunctionScoreQuery.ScoreMode.SUM)
.setMinScore(1)
.maxBoost(100);
FunctionScoreQueryBuilder rewrite = (FunctionScoreQueryBuilder) functionScoreQueryBuilder.rewrite(createShardContext());
assertNotSame(functionScoreQueryBuilder, rewrite);
assertEquals(rewrite.query(), new TermQueryBuilder(STRING_FIELD_NAME, "bar"));
assertEquals(rewrite.query(), new TermQueryBuilder(TEXT_FIELD_NAME, "bar"));
assertEquals(rewrite.boostMode(), CombineFunction.REPLACE);
assertEquals(rewrite.scoreMode(), FunctionScoreQuery.ScoreMode.SUM);
assertEquals(rewrite.getMinScore(), 1f, 0.0001);
@ -658,18 +658,18 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
}
public void testRewriteWithFunction() throws IOException {
QueryBuilder firstFunction = new WrapperQueryBuilder(new TermQueryBuilder(STRING_FIELD_NAME_2, "1").toString());
TermQueryBuilder secondFunction = new TermQueryBuilder(STRING_FIELD_NAME_2, "2");
QueryBuilder queryBuilder = randomBoolean() ? new WrapperQueryBuilder(new TermQueryBuilder(STRING_FIELD_NAME, "bar").toString())
: new TermQueryBuilder(STRING_FIELD_NAME, "bar");
QueryBuilder firstFunction = new WrapperQueryBuilder(new TermQueryBuilder(KEYWORD_FIELD_NAME, "1").toString());
TermQueryBuilder secondFunction = new TermQueryBuilder(KEYWORD_FIELD_NAME, "2");
QueryBuilder queryBuilder = randomBoolean() ? new WrapperQueryBuilder(new TermQueryBuilder(TEXT_FIELD_NAME, "bar").toString())
: new TermQueryBuilder(TEXT_FIELD_NAME, "bar");
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder,
new FunctionScoreQueryBuilder.FilterFunctionBuilder[] {
new FunctionScoreQueryBuilder.FilterFunctionBuilder(firstFunction, new RandomScoreFunctionBuilder()),
new FunctionScoreQueryBuilder.FilterFunctionBuilder(secondFunction, new RandomScoreFunctionBuilder()) });
FunctionScoreQueryBuilder rewrite = (FunctionScoreQueryBuilder) functionScoreQueryBuilder.rewrite(createShardContext());
assertNotSame(functionScoreQueryBuilder, rewrite);
assertEquals(rewrite.query(), new TermQueryBuilder(STRING_FIELD_NAME, "bar"));
assertEquals(rewrite.filterFunctionBuilders()[0].getFilter(), new TermQueryBuilder(STRING_FIELD_NAME_2, "1"));
assertEquals(rewrite.query(), new TermQueryBuilder(TEXT_FIELD_NAME, "bar"));
assertEquals(rewrite.filterFunctionBuilders()[0].getFilter(), new TermQueryBuilder(KEYWORD_FIELD_NAME, "1"));
assertSame(rewrite.filterFunctionBuilders()[1].getFilter(), secondFunction);
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.test;
import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.carrotsearch.randomizedtesting.SeedUtils;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.util.Accountable;
import org.elasticsearch.Version;
@ -104,9 +105,9 @@ import static java.util.stream.Collectors.toList;
public abstract class AbstractBuilderTestCase extends ESTestCase {
public static final String STRING_FIELD_NAME = "mapped_string";
public static final String STRING_ALIAS_FIELD_NAME = "mapped_string_alias";
protected static final String STRING_FIELD_NAME_2 = "mapped_string_2";
public static final String TEXT_FIELD_NAME = "mapped_string";
public static final String TEXT_ALIAS_FIELD_NAME = "mapped_string_alias";
protected static final String KEYWORD_FIELD_NAME = "mapped_string_2";
protected static final String INT_FIELD_NAME = "mapped_int";
protected static final String INT_ALIAS_FIELD_NAME = "mapped_int_field_alias";
protected static final String INT_RANGE_FIELD_NAME = "mapped_int_range";
@ -120,17 +121,17 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
protected static final String GEO_POINT_FIELD_NAME = "mapped_geo_point";
protected static final String GEO_POINT_ALIAS_FIELD_NAME = "mapped_geo_point_alias";
protected static final String GEO_SHAPE_FIELD_NAME = "mapped_geo_shape";
protected static final String[] MAPPED_FIELD_NAMES = new String[]{STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME,
protected static final String[] MAPPED_FIELD_NAMES = new String[]{TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME,
INT_FIELD_NAME, INT_RANGE_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_NANOS_FIELD_NAME, DATE_FIELD_NAME,
DATE_RANGE_FIELD_NAME, OBJECT_FIELD_NAME, GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME,
GEO_SHAPE_FIELD_NAME};
protected static final String[] MAPPED_LEAF_FIELD_NAMES = new String[]{STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME,
protected static final String[] MAPPED_LEAF_FIELD_NAMES = new String[]{TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME,
INT_FIELD_NAME, INT_RANGE_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_NANOS_FIELD_NAME,
DATE_FIELD_NAME, DATE_RANGE_FIELD_NAME, GEO_POINT_FIELD_NAME, GEO_POINT_ALIAS_FIELD_NAME};
private static final Map<String, String> ALIAS_TO_CONCRETE_FIELD_NAME = new HashMap<>();
static {
ALIAS_TO_CONCRETE_FIELD_NAME.put(STRING_ALIAS_FIELD_NAME, STRING_FIELD_NAME);
ALIAS_TO_CONCRETE_FIELD_NAME.put(TEXT_ALIAS_FIELD_NAME, TEXT_FIELD_NAME);
ALIAS_TO_CONCRETE_FIELD_NAME.put(INT_ALIAS_FIELD_NAME, INT_FIELD_NAME);
ALIAS_TO_CONCRETE_FIELD_NAME.put(DATE_ALIAS_FIELD_NAME, DATE_FIELD_NAME);
ALIAS_TO_CONCRETE_FIELD_NAME.put(GEO_POINT_ALIAS_FIELD_NAME, GEO_POINT_FIELD_NAME);
@ -377,9 +378,9 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
if (registerType) {
mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc",
STRING_FIELD_NAME, "type=text",
STRING_FIELD_NAME_2, "type=keyword",
STRING_ALIAS_FIELD_NAME, "type=alias,path=" + STRING_FIELD_NAME,
TEXT_FIELD_NAME, "type=text",
KEYWORD_FIELD_NAME, "type=keyword",
TEXT_ALIAS_FIELD_NAME, "type=alias,path=" + TEXT_FIELD_NAME,
INT_FIELD_NAME, "type=integer",
INT_ALIAS_FIELD_NAME, "type=alias,path=" + INT_FIELD_NAME,
INT_RANGE_FIELD_NAME, "type=integer_range",

View File

@ -624,14 +624,14 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
/**
* create a random value for either {@link AbstractQueryTestCase#BOOLEAN_FIELD_NAME}, {@link AbstractQueryTestCase#INT_FIELD_NAME},
* {@link AbstractQueryTestCase#DOUBLE_FIELD_NAME}, {@link AbstractQueryTestCase#STRING_FIELD_NAME} or
* {@link AbstractQueryTestCase#DOUBLE_FIELD_NAME}, {@link AbstractQueryTestCase#TEXT_FIELD_NAME} or
* {@link AbstractQueryTestCase#DATE_FIELD_NAME} or {@link AbstractQueryTestCase#DATE_NANOS_FIELD_NAME} or a String value by default
*/
protected static Object getRandomValueForFieldName(String fieldName) {
Object value;
switch (fieldName) {
case STRING_FIELD_NAME:
case STRING_ALIAS_FIELD_NAME:
case TEXT_FIELD_NAME:
case TEXT_ALIAS_FIELD_NAME:
if (rarely()) {
// unicode in 10% cases
JsonStringEncoder encoder = JsonStringEncoder.getInstance();
@ -798,7 +798,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
}
public boolean isTextField(String fieldName) {
return fieldName.equals(STRING_FIELD_NAME) || fieldName.equals(STRING_ALIAS_FIELD_NAME);
return fieldName.equals(TEXT_FIELD_NAME) || fieldName.equals(TEXT_ALIAS_FIELD_NAME);
}
/**

View File

@ -56,7 +56,7 @@ public class PinnedQueryBuilderTests extends AbstractQueryTestCase<PinnedQueryBu
break;
case 1:
if (randomBoolean()) {
fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME);
fieldName = randomFrom(TEXT_FIELD_NAME, TEXT_ALIAS_FIELD_NAME);
}
if (frequently()) {
value = randomAlphaOfLengthBetween(1, 10);

View File

@ -238,7 +238,7 @@ public class ShapeQueryBuilderTests extends AbstractQueryTestCase<ShapeQueryBuil
public void testWrongFieldType() {
Geometry shape = ShapeTestUtils.randomGeometry(false);
final ShapeQueryBuilder queryBuilder = new ShapeQueryBuilder(STRING_FIELD_NAME, shape);
final ShapeQueryBuilder queryBuilder = new ShapeQueryBuilder(TEXT_FIELD_NAME, shape);
QueryShardException e = expectThrows(QueryShardException.class, () -> queryBuilder.toQuery(createShardContext()));
assertThat(e.getMessage(), containsString("Field [mapped_string] is not of type [shape] but of type [text]"));
}