Skip to content

Commit

Permalink
Revert removal of 7.x related code from analysis common
Browse files Browse the repository at this point in the history
This reverts elastic#113009 and re-adds previous v7 tests since we
now support v7 indices as read-only on v9.
  • Loading branch information
cbuescher committed Dec 18, 2024
1 parent 3fce042 commit 5ed66a3
Showing 1 changed file with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ public void testNGramFilterInCustomAnalyzerDeprecationError() throws IOException
ex.getMessage()
);
}

final Settings settingsPre7 = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put(
IndexMetadata.SETTING_VERSION_CREATED,
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_6_0)
)
.put("index.analysis.analyzer.custom_analyzer.type", "custom")
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard")
.putList("index.analysis.analyzer.custom_analyzer.filter", "my_ngram")
.put("index.analysis.filter.my_ngram.type", "nGram")
.build();
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) {
createTestAnalysis(IndexSettingsModule.newIndexSettings("index", settingsPre7), settingsPre7, commonAnalysisPlugin);
assertWarnings(
"The [nGram] token filter name is deprecated and will be removed in a future version. "
+ "Please change the filter name to [ngram] instead."
);
}
}

/**
Expand Down Expand Up @@ -83,13 +102,66 @@ public void testEdgeNGramFilterInCustomAnalyzerDeprecationError() throws IOExcep
ex.getMessage()
);
}

final Settings settingsPre7 = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put(
IndexMetadata.SETTING_VERSION_CREATED,
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_6_0)
)
.put("index.analysis.analyzer.custom_analyzer.type", "custom")
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard")
.putList("index.analysis.analyzer.custom_analyzer.filter", "my_ngram")
.put("index.analysis.filter.my_ngram.type", "edgeNGram")
.build();

try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) {
createTestAnalysis(IndexSettingsModule.newIndexSettings("index", settingsPre7), settingsPre7, commonAnalysisPlugin);
assertWarnings(
"The [edgeNGram] token filter name is deprecated and will be removed in a future version. "
+ "Please change the filter name to [edge_ngram] instead."
);
}
}

/**
* Check that we log a deprecation warning for "nGram" and "edgeNGram" tokenizer names with 7.6 and
* disallow usages for indices created after 8.0
*/
public void testNGramTokenizerDeprecation() throws IOException {
// tests for prebuilt tokenizer
doTestPrebuiltTokenizerDeprecation(
"nGram",
"ngram",
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
false
);
doTestPrebuiltTokenizerDeprecation(
"edgeNGram",
"edge_ngram",
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
false
);
doTestPrebuiltTokenizerDeprecation(
"nGram",
"ngram",
IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.V_7_6_0,
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
),
true
);
doTestPrebuiltTokenizerDeprecation(
"edgeNGram",
"edge_ngram",
IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.V_7_6_0,
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
),
true
);
expectThrows(
IllegalArgumentException.class,
() -> doTestPrebuiltTokenizerDeprecation(
Expand All @@ -108,6 +180,40 @@ public void testNGramTokenizerDeprecation() throws IOException {
true
)
);

// same batch of tests for custom tokenizer definition in the settings
doTestCustomTokenizerDeprecation(
"nGram",
"ngram",
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
false
);
doTestCustomTokenizerDeprecation(
"edgeNGram",
"edge_ngram",
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_7_0_0, IndexVersions.V_7_5_2),
false
);
doTestCustomTokenizerDeprecation(
"nGram",
"ngram",
IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.V_7_6_0,
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
),
true
);
doTestCustomTokenizerDeprecation(
"edgeNGram",
"edge_ngram",
IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.V_7_6_0,
IndexVersion.max(IndexVersions.V_7_6_0, IndexVersionUtils.getPreviousVersion(IndexVersions.V_8_0_0))
),
true
);
expectThrows(
IllegalArgumentException.class,
() -> doTestCustomTokenizerDeprecation(
Expand Down

0 comments on commit 5ed66a3

Please sign in to comment.