Skip to content

Commit

Permalink
Add full cluster restart test
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuescher committed Sep 24, 2024
1 parent 7de8e97 commit 6fdeb79
Showing 1 changed file with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.analysis.Analysis;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
import org.elasticsearch.test.NotEqualMessageBuilder;
Expand Down Expand Up @@ -1726,6 +1727,106 @@ public void testSystemIndexMetadataIsUpgraded() throws Exception {
}
}

/**
* This test ensures that search results on old indices using "persian" analyzer don't change
* after we introduce Lucene 10
*/
public void testPersianAnalyzerBWC() throws Exception {
var originalClusterLegacyPersianAnalyzer = oldClusterHasFeature(Analysis.PERSIAN_ANALYZER_WITH_STEMMER) == false;
assumeTrue("Don't run this test if both versions already support stemming", originalClusterLegacyPersianAnalyzer);
final String indexName = "test_persian_stemmer";
Settings idxSettings = indexSettings(1, 1).build();
String mapping = """
{
"properties": {
"textfield" : {
"type": "text",
"analyzer": "persian"
}
}
}
""";

String query = """
{
"query": {
"match": {
"textfield": "كتابها"
}
}
}
""";

if (isRunningAgainstOldCluster()) {
createIndex(client(), indexName, idxSettings, mapping);
ensureGreen(indexName);

assertOK(
client().performRequest(
newXContentRequest(
HttpMethod.POST,
"/" + indexName + "/" + "_doc/1",
(builder, params) -> builder.field("textfield", "كتابها")
)
)
);
assertOK(
client().performRequest(
newXContentRequest(
HttpMethod.POST,
"/" + indexName + "/" + "_doc/2",
(builder, params) -> builder.field("textfield", "كتاب")
)
)
);
refresh(indexName);

assertNumHits(indexName, 2, 1);

Request searchRequest = new Request("POST", "/" + indexName + "/_search");
searchRequest.setJsonEntity(query);
assertTotalHits(1, entityAsMap(client().performRequest(searchRequest)));
} else {
// old index should still only return one doc
Request searchRequest = new Request("POST", "/" + indexName + "/_search");
searchRequest.setJsonEntity(query);
assertTotalHits(1, entityAsMap(client().performRequest(searchRequest)));

String newIndexName = indexName + "_new";
createIndex(client(), newIndexName, idxSettings, mapping);
ensureGreen(newIndexName);

assertOK(
client().performRequest(
newXContentRequest(
HttpMethod.POST,
"/" + newIndexName + "/" + "_doc/1",
(builder, params) -> builder.field("textfield", "كتابها")
)
)
);
assertOK(
client().performRequest(
newXContentRequest(
HttpMethod.POST,
"/" + newIndexName + "/" + "_doc/2",
(builder, params) -> builder.field("textfield", "كتاب")
)
)
);
refresh(newIndexName);

searchRequest = new Request("POST", "/" + newIndexName + "/_search");
searchRequest.setJsonEntity(query);
assertTotalHits(2, entityAsMap(client().performRequest(searchRequest)));

// searching both indices (old and new analysis version) we should get 1 hit from the old and 2 from the new index
searchRequest = new Request("POST", "/" + indexName + "," + newIndexName + "/_search");
searchRequest.setJsonEntity(query);
assertTotalHits(3, entityAsMap(client().performRequest(searchRequest)));
}
}

/**
* This test ensures that soft deletes are enabled a when upgrading a pre-8 cluster to 8.0+
*/
Expand Down

0 comments on commit 6fdeb79

Please sign in to comment.