Skip to content

Commit 13c75c0

Browse files
authored
Test/legacy similarity settings - archive indices (#120352)
Create a test for archive indices with index mapping with legacy similarity settings
1 parent 61e9a22 commit 13c75c0

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldMappingsIT.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.junit.Before;
3434

3535
import java.io.IOException;
36+
import java.util.ArrayList;
3637
import java.util.Arrays;
3738
import java.util.List;
3839
import java.util.Map;
@@ -81,11 +82,9 @@ public void setupIndex() throws IOException {
8182

8283
String repoName = "old_mappings_repo";
8384
String snapshotName = "snap";
84-
List<String> indices;
85+
List<String> indices = new ArrayList<>(List.of("filebeat", "custom", "nested", "standard_token_filter", "similarity"));
8586
if (oldVersion.before(Version.fromString("6.0.0"))) {
86-
indices = Arrays.asList("filebeat", "winlogbeat", "custom", "nested", "standard_token_filter");
87-
} else {
88-
indices = Arrays.asList("filebeat", "custom", "nested", "standard_token_filter");
87+
indices.add("winlogbeat");
8988
}
9089

9190
int oldEsPort = Integer.parseInt(System.getProperty("tests.es.port"));
@@ -109,6 +108,22 @@ public void setupIndex() throws IOException {
109108
)
110109
)
111110
);
111+
assertOK(
112+
oldEs.performRequest(
113+
createIndex(
114+
"similarity",
115+
"similarity.json",
116+
Settings.builder()
117+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
118+
.put("index.similarity.custom_dfr.type", "DFR")
119+
.put("index.similarity.custom_dfr.basic_model", randomFrom(Arrays.asList("be", "d", "p")))
120+
.put("index.similarity.custom_dfr.after_effect", "no")
121+
.put("index.similarity.custom_dfr.normalization", "h2")
122+
.put("index.similarity.custom_dfr.normalization.h2.c", "3.0")
123+
.build()
124+
)
125+
)
126+
);
112127
assertOK(oldEs.performRequest(createIndex("custom", "custom.json")));
113128
assertOK(oldEs.performRequest(createIndex("nested", "nested.json")));
114129

@@ -166,6 +181,12 @@ public void setupIndex() throws IOException {
166181
doc4.setJsonEntity(Strings.toString(bodyDoc4));
167182
assertOK(oldEs.performRequest(doc4));
168183

184+
Request doc5 = new Request("POST", "/" + "similarity" + "/" + "doc");
185+
doc5.addParameter("refresh", "true");
186+
XContentBuilder bodyDoc5 = XContentFactory.jsonBuilder().startObject().field("content", "Twin Peaks!").endObject();
187+
doc5.setJsonEntity(Strings.toString(bodyDoc5));
188+
assertOK(oldEs.performRequest(doc5));
189+
169190
// register repo on old ES and take snapshot
170191
Request createRepoRequest = new Request("PUT", "/_snapshot/" + repoName);
171192
createRepoRequest.setJsonEntity(Strings.format("""
@@ -232,7 +253,15 @@ public void testMappingOk() throws IOException {
232253
}
233254

234255
public void testStandardTokenFilter() throws IOException {
235-
Request search = new Request("POST", "/" + "standard_token_filter" + "/_search");
256+
assertMatchAll("standard_token_filter");
257+
}
258+
259+
public void testSimilarityWithLegacySettings() throws IOException {
260+
assertMatchAll("similarity");
261+
}
262+
263+
private void assertMatchAll(String indexName) throws IOException {
264+
Request search = new Request("POST", "/" + indexName + "/_search");
236265
XContentBuilder query = XContentBuilder.builder(XContentType.JSON.xContent())
237266
.startObject()
238267
.startObject("query")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"_default_": {
2+
"properties": {
3+
"content": {
4+
"type": "text",
5+
"similarity": "custom_dfr"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)