Fix test bug in SpanMultiTermQueryBuilderTests (#62833)

This test checks to see if the index has been created before version 6.4, in which
case index prefixes are unavailable and so it expects to see a span multi-term
wrapper. However, the production code doesn't bother with checking for versions,
because if the field in question is configured with index_prefixes then it knows that
it must have been created post 6.4 (you can't merge in a new index_prefixes
configuration).

This commit alters the test to remove the random version checks, as we know we
will always have a prefix field available in this scenario.

Fixes #58199
This commit is contained in:
Alan Woodward 2020-09-23 17:02:12 +01:00 committed by GitHub
parent 0baefc8ddc
commit 7984e4e89f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 19 deletions

View File

@ -39,7 +39,6 @@ import org.apache.lucene.search.spans.SpanMultiTermQueryWrapper;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.store.Directory;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -53,9 +52,9 @@ import java.io.IOException;
import static java.util.Collections.singleton;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.either;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.either;
import static org.hamcrest.CoreMatchers.startsWith;
public class SpanMultiTermQueryBuilderTests extends AbstractQueryTestCase<SpanMultiTermQueryBuilder> {
@ -189,28 +188,18 @@ public class SpanMultiTermQueryBuilderTests extends AbstractQueryTestCase<SpanMu
assertThat(query, instanceOf(SpanQuery.class));
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/58199")
public void testToQueryInnerTermQuery() throws IOException {
String fieldName = randomFrom("prefix_field", "prefix_field_alias");
final QueryShardContext context = createShardContext();
{
Query query = new SpanMultiTermQueryBuilder(new PrefixQueryBuilder(fieldName, "foo")).toQuery(context);
if (context.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_4_0)) {
assertThat(query, instanceOf(FieldMaskingSpanQuery.class));
FieldMaskingSpanQuery fieldQuery = (FieldMaskingSpanQuery) query;
assertThat(fieldQuery.getMaskedQuery(), instanceOf(SpanTermQuery.class));
assertThat(fieldQuery.getField(), equalTo("prefix_field"));
SpanTermQuery termQuery = (SpanTermQuery) fieldQuery.getMaskedQuery();
assertThat(termQuery.getTerm().field(), equalTo("prefix_field._index_prefix"));
assertThat(termQuery.getTerm().text(), equalTo("foo"));
} else {
assertThat(query, instanceOf(SpanMultiTermQueryWrapper.class));
SpanMultiTermQueryWrapper wrapper = (SpanMultiTermQueryWrapper) query;
assertThat(wrapper.getWrappedQuery(), instanceOf(PrefixQuery.class));
PrefixQuery prefixQuery = (PrefixQuery) wrapper.getWrappedQuery();
assertThat(prefixQuery.getField(), equalTo("prefix_field"));
assertThat(prefixQuery.getPrefix().text(), equalTo("foo"));
}
assertThat(query, instanceOf(FieldMaskingSpanQuery.class));
FieldMaskingSpanQuery fieldQuery = (FieldMaskingSpanQuery) query;
assertThat(fieldQuery.getMaskedQuery(), instanceOf(SpanTermQuery.class));
assertThat(fieldQuery.getField(), equalTo("prefix_field"));
SpanTermQuery termQuery = (SpanTermQuery) fieldQuery.getMaskedQuery();
assertThat(termQuery.getTerm().field(), equalTo("prefix_field._index_prefix"));
assertThat(termQuery.getTerm().text(), equalTo("foo"));
}
{