Skip to content

Commit b076249

Browse files
authored
Backport to version 8.x (#120263)
This is a manual backport of #120107
1 parent dbbcc53 commit b076249

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
### Project repository-old-versions
3+
4+
Test project, for Lucene indices backward compatibility with versions before N-2
5+
(Archive-indices).
6+
7+
The project aims to do the following
8+
1. Deploy a cluster in version 5 / 6
9+
2. Create an index, add a document, verify index integrity, create a snapshot
10+
3. Deploy a cluster in the Current version
11+
4. Restore an index and verify index integrity

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

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.client.ResponseException;
1717
import org.elasticsearch.client.RestClient;
1818
import org.elasticsearch.client.WarningsHandler;
19+
import org.elasticsearch.cluster.metadata.IndexMetadata;
1920
import org.elasticsearch.common.Strings;
2021
import org.elasticsearch.common.settings.SecureString;
2122
import org.elasticsearch.common.settings.Settings;
@@ -24,6 +25,7 @@
2425
import org.elasticsearch.core.Booleans;
2526
import org.elasticsearch.core.PathUtils;
2627
import org.elasticsearch.test.rest.ESRestTestCase;
28+
import org.elasticsearch.xcontent.ToXContent;
2729
import org.elasticsearch.xcontent.XContentBuilder;
2830
import org.elasticsearch.xcontent.XContentFactory;
2931
import org.elasticsearch.xcontent.XContentType;
@@ -35,6 +37,7 @@
3537
import java.util.Map;
3638
import java.util.stream.Collectors;
3739

40+
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
3841
import static org.hamcrest.Matchers.containsString;
3942
import static org.hamcrest.Matchers.hasKey;
4043
import static org.hamcrest.Matchers.hasSize;
@@ -79,9 +82,9 @@ public void setupIndex() throws IOException {
7982
String snapshotName = "snap";
8083
List<String> indices;
8184
if (oldVersion.before(Version.fromString("6.0.0"))) {
82-
indices = Arrays.asList("filebeat", "winlogbeat", "custom", "nested");
85+
indices = Arrays.asList("filebeat", "winlogbeat", "custom", "nested", "standard_token_filter");
8386
} else {
84-
indices = Arrays.asList("filebeat", "custom", "nested");
87+
indices = Arrays.asList("filebeat", "custom", "nested", "standard_token_filter");
8588
}
8689

8790
int oldEsPort = Integer.parseInt(System.getProperty("tests.es.port"));
@@ -91,6 +94,20 @@ public void setupIndex() throws IOException {
9194
if (oldVersion.before(Version.fromString("6.0.0"))) {
9295
assertOK(oldEs.performRequest(createIndex("winlogbeat", "winlogbeat.json")));
9396
}
97+
assertOK(
98+
oldEs.performRequest(
99+
createIndex(
100+
"standard_token_filter",
101+
"standard_token_filter.json",
102+
Settings.builder()
103+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
104+
.put("index.analysis.analyzer.custom_analyzer.type", "custom")
105+
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard")
106+
.put("index.analysis.analyzer.custom_analyzer.filter", "standard")
107+
.build()
108+
)
109+
)
110+
);
94111
assertOK(oldEs.performRequest(createIndex("custom", "custom.json")));
95112
assertOK(oldEs.performRequest(createIndex("nested", "nested.json")));
96113

@@ -142,6 +159,12 @@ public void setupIndex() throws IOException {
142159
doc3.setJsonEntity(Strings.toString(bodyDoc3));
143160
assertOK(oldEs.performRequest(doc3));
144161

162+
Request doc4 = new Request("POST", "/" + "standard_token_filter" + "/" + "doc");
163+
doc4.addParameter("refresh", "true");
164+
XContentBuilder bodyDoc4 = XContentFactory.jsonBuilder().startObject().field("content", "Doc 1").endObject();
165+
doc4.setJsonEntity(Strings.toString(bodyDoc4));
166+
assertOK(oldEs.performRequest(doc4));
167+
145168
// register repo on old ES and take snapshot
146169
Request createRepoRequest = new Request("PUT", "/_snapshot/" + repoName);
147170
createRepoRequest.setJsonEntity(Strings.format("""
@@ -170,15 +193,21 @@ public void setupIndex() throws IOException {
170193
}
171194

172195
private Request createIndex(String indexName, String file) throws IOException {
196+
return createIndex(indexName, file, Settings.EMPTY);
197+
}
198+
199+
private Request createIndex(String indexName, String file, Settings settings) throws IOException {
173200
Request createIndex = new Request("PUT", "/" + indexName);
174201
int numberOfShards = randomIntBetween(1, 3);
175202

176-
XContentBuilder builder = XContentFactory.jsonBuilder()
177-
.startObject()
178-
.startObject("settings")
179-
.field("index.number_of_shards", numberOfShards)
180-
.endObject()
181-
.startObject("mappings");
203+
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
204+
205+
builder.startObject("settings");
206+
builder.field(SETTING_NUMBER_OF_SHARDS, numberOfShards);
207+
settings.toXContent(builder, ToXContent.EMPTY_PARAMS);
208+
builder.endObject();
209+
210+
builder.startObject("mappings");
182211
builder.rawValue(OldMappingsIT.class.getResourceAsStream(file), XContentType.JSON);
183212
builder.endObject().endObject();
184213

@@ -198,6 +227,21 @@ public void testMappingOk() throws IOException {
198227
}
199228
}
200229

230+
public void testStandardTokenFilter() throws IOException {
231+
Request search = new Request("POST", "/" + "standard_token_filter" + "/_search");
232+
XContentBuilder query = XContentBuilder.builder(XContentType.JSON.xContent())
233+
.startObject()
234+
.startObject("query")
235+
.startObject("match_all")
236+
.endObject()
237+
.endObject()
238+
.endObject();
239+
search.setJsonEntity(Strings.toString(query));
240+
Map<String, Object> response = entityAsMap(client().performRequest(search));
241+
List<?> hits = (List<?>) (XContentMapValues.extractValue("hits.hits", response));
242+
assertThat(hits, hasSize(1));
243+
}
244+
201245
public void testSearchKeyword() throws IOException {
202246
Request search = new Request("POST", "/" + "custom" + "/_search");
203247
XContentBuilder query = XContentBuilder.builder(XContentType.JSON.xContent())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"_default_": {
2+
"properties": {
3+
"content": {
4+
"type": "text",
5+
"analyzer": "custom_analyzer"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)