[Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery BWC

Handle BWC version in this test.

Closes #27246
This commit is contained in:
Jim Ferenczi 2017-11-03 14:17:11 +01:00
parent 8b4a92fbb7
commit 262422375e
1 changed files with 8 additions and 5 deletions

View File

@ -46,6 +46,7 @@ import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.compress.CompressedXContent;
@ -804,17 +805,19 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
QueryShardContext context = createShardContext();
QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder(STRING_FIELD_NAME + ":*");
Query query = queryBuilder.toQuery(context);
Query expected;
if (getCurrentTypes().length > 0) {
expected = new ConstantScoreQuery(new NormsFieldExistsQuery(STRING_FIELD_NAME));
if (context.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)) {
assertThat(query, equalTo(new ConstantScoreQuery(new NormsFieldExistsQuery(STRING_FIELD_NAME))));
} else {
expected = new MatchNoDocsQuery();
assertThat(query, equalTo(new ConstantScoreQuery(new TermQuery(new Term("_field_names", STRING_FIELD_NAME)))));
}
} else {
assertThat(query, equalTo(new MatchNoDocsQuery()));
}
assertThat(query, equalTo(expected));
queryBuilder = new QueryStringQueryBuilder("*:*");
query = queryBuilder.toQuery(context);
expected = new MatchAllDocsQuery();
Query expected = new MatchAllDocsQuery();
assertThat(query, equalTo(expected));
queryBuilder = new QueryStringQueryBuilder("*");