Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore WildcardFieldMapperTests#testBWCIndexVersion #119093

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
import org.elasticsearch.index.fielddata.FieldDataContext;
import org.elasticsearch.index.fielddata.IndexFieldData;
Expand Down Expand Up @@ -106,6 +107,7 @@ static SearchExecutionContext createMockSearchExecutionContext(boolean allowExpe

static final int MAX_FIELD_LENGTH = 30;
static WildcardFieldMapper wildcardFieldType;
static WildcardFieldMapper wildcardFieldType79;
static KeywordFieldMapper keywordFieldType;
private DirectoryReader rewriteReader;
private BaseDirectoryWrapper rewriteDir;
Expand All @@ -127,6 +129,9 @@ public void setUp() throws Exception {
builder.ignoreAbove(MAX_FIELD_LENGTH);
wildcardFieldType = builder.build(MapperBuilderContext.root(false, false));

Builder builder79 = new WildcardFieldMapper.Builder(WILDCARD_FIELD_NAME, IndexVersions.V_7_9_0);
wildcardFieldType79 = builder79.build(MapperBuilderContext.root(false, false));

org.elasticsearch.index.mapper.KeywordFieldMapper.Builder kwBuilder = new KeywordFieldMapper.Builder(
KEYWORD_FIELD_NAME,
IndexVersion.current()
Expand Down Expand Up @@ -207,6 +212,37 @@ public void testIgnoreAbove() throws IOException {
assertTrue(fields.stream().anyMatch(field -> "field".equals(field.stringValue())));
}

public void testBWCIndexVersion() throws IOException {
// Create old format index using wildcard ngram analyzer used in 7.9 launch
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(WildcardFieldMapper.WILDCARD_ANALYZER_7_9);
iwc.setMergePolicy(newTieredMergePolicy(random()));
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);

Document doc = new Document();
LuceneDocument parseDoc = new LuceneDocument();
addFields(parseDoc, doc, "a b");
indexDoc(parseDoc, doc, iw);

iw.forceMerge(1);
DirectoryReader reader = iw.getReader();
IndexSearcher searcher = newSearcher(reader);
iw.close();

// Unnatural circumstance - testing we fail if we were to use the new analyzer on old index
Query oldWildcardFieldQuery = wildcardFieldType.fieldType().wildcardQuery("a b", null, null);
TopDocs oldWildcardFieldTopDocs = searcher.search(oldWildcardFieldQuery, 10, Sort.INDEXORDER);
assertThat(oldWildcardFieldTopDocs.totalHits.value(), equalTo(0L));

// Natural circumstance test we revert to the old analyzer for old indices
Query wildcardFieldQuery = wildcardFieldType79.fieldType().wildcardQuery("a b", null, null);
TopDocs wildcardFieldTopDocs = searcher.search(wildcardFieldQuery, 10, Sort.INDEXORDER);
assertThat(wildcardFieldTopDocs.totalHits.value(), equalTo(1L));

reader.close();
dir.close();
}

// Test long query strings don't cause exceptions
public void testTooBigQueryField() throws IOException {
Directory dir = newDirectory();
Expand Down