Skip to content

Commit 00d8fd7

Browse files
authored
Remove old synthetic source mapping config (elastic#115889) (elastic#115961)
This change replaces the old synthetic source config in mappings with the newly introduced index setting. Closes elastic#115859
1 parent a5406ce commit 00d8fd7

File tree

20 files changed

+163
-202
lines changed

20 files changed

+163
-202
lines changed

modules/mapper-extras/src/internalClusterTest/java/org/elasticsearch/index/mapper/MatchOnlyTextMapperIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.action.bulk.BulkRequestBuilder;
1313
import org.elasticsearch.action.bulk.BulkResponse;
1414
import org.elasticsearch.action.support.WriteRequest;
15+
import org.elasticsearch.common.settings.Settings;
1516
import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin;
1617
import org.elasticsearch.index.query.QueryBuilders;
1718
import org.elasticsearch.plugins.Plugin;
@@ -89,13 +90,14 @@ public void testHighlightingWithMatchOnlyTextFieldSyntheticSource() throws IOExc
8990
// load the source.
9091

9192
String mappings = """
92-
{ "_source" : { "mode" : "synthetic" },
93+
{
9394
"properties" : {
9495
"message" : { "type" : "match_only_text" }
9596
}
9697
}
9798
""";
98-
assertAcked(prepareCreate("test").setMapping(mappings));
99+
Settings.Builder settings = Settings.builder().put(indexSettings()).put("index.mapping.source.mode", "synthetic");
100+
assertAcked(prepareCreate("test").setSettings(settings).setMapping(mappings));
99101
BulkRequestBuilder bulk = client().prepareBulk("test").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
100102
for (int i = 0; i < 2000; i++) {
101103
bulk.add(

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapperTests.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ protected Object getSampleValueForDocument() {
6464
}
6565

6666
public void testExistsStandardSource() throws IOException {
67-
assertExistsQuery(createMapperService(testMapping(false)));
67+
assertExistsQuery(createMapperService(fieldMapping(b -> b.field("type", "match_only_text"))));
6868
}
6969

7070
public void testExistsSyntheticSource() throws IOException {
71-
assertExistsQuery(createMapperService(testMapping(true)));
71+
assertExistsQuery(createSytheticSourceMapperService(fieldMapping(b -> b.field("type", "match_only_text"))));
7272
}
7373

7474
public void testPhraseQueryStandardSource() throws IOException {
75-
assertPhraseQuery(createMapperService(testMapping(false)));
75+
assertPhraseQuery(createMapperService(fieldMapping(b -> b.field("type", "match_only_text"))));
7676
}
7777

7878
public void testPhraseQuerySyntheticSource() throws IOException {
79-
assertPhraseQuery(createMapperService(testMapping(true)));
79+
assertPhraseQuery(createSytheticSourceMapperService(fieldMapping(b -> b.field("type", "match_only_text"))));
8080
}
8181

8282
private void assertPhraseQuery(MapperService mapperService) throws IOException {
@@ -104,13 +104,6 @@ protected void registerParameters(ParameterChecker checker) throws IOException {
104104
);
105105
}
106106

107-
private static XContentBuilder testMapping(boolean syntheticSource) throws IOException {
108-
if (syntheticSource) {
109-
return syntheticSourceMapping(b -> b.startObject("field").field("type", "match_only_text").endObject());
110-
}
111-
return fieldMapping(b -> b.field("type", "match_only_text"));
112-
}
113-
114107
@Override
115108
protected void minimalMapping(XContentBuilder b) throws IOException {
116109
b.field("type", "match_only_text");
@@ -256,7 +249,7 @@ public void testDocValues() throws IOException {
256249
}
257250

258251
public void testDocValuesLoadedFromSynthetic() throws IOException {
259-
MapperService mapper = createMapperService(syntheticSourceFieldMapping(b -> b.field("type", "match_only_text")));
252+
MapperService mapper = createSytheticSourceMapperService(fieldMapping(b -> b.field("type", "match_only_text")));
260253
assertScriptDocValues(mapper, "foo", equalTo(List.of("foo")));
261254
}
262255

server/src/test/java/org/elasticsearch/index/mapper/DocCountFieldMapperTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ public void testInvalidDocument_ArrayDocCount() throws Exception {
8484
}
8585

8686
public void testSyntheticSource() throws IOException {
87-
DocumentMapper mapper = createDocumentMapper(syntheticSourceMapping(b -> {}));
87+
DocumentMapper mapper = createSytheticSourceMapperService(topMapping(b -> {})).documentMapper();
8888
assertThat(syntheticSource(mapper, b -> b.field(CONTENT_TYPE, 10)), equalTo("{\"_doc_count\":10}"));
8989
}
9090

9191
public void testSyntheticSourceMany() throws IOException {
92-
MapperService mapper = createMapperService(syntheticSourceMapping(b -> b.startObject("doc").field("type", "integer").endObject()));
92+
MapperService mapper = createSytheticSourceMapperService(mapping(b -> b.startObject("doc").field("type", "integer").endObject()));
9393
List<Integer> counts = randomList(2, 10000, () -> between(1, Integer.MAX_VALUE));
9494
withLuceneIndex(mapper, iw -> {
9595
int d = 0;
@@ -116,7 +116,7 @@ public void testSyntheticSourceMany() throws IOException {
116116
}
117117

118118
public void testSyntheticSourceManyDoNotHave() throws IOException {
119-
MapperService mapper = createMapperService(syntheticSourceMapping(b -> b.startObject("doc").field("type", "integer").endObject()));
119+
MapperService mapper = createSytheticSourceMapperService(mapping(b -> b.startObject("doc").field("type", "integer").endObject()));
120120
List<Integer> counts = randomList(2, 10000, () -> randomBoolean() ? null : between(1, Integer.MAX_VALUE));
121121
withLuceneIndex(mapper, iw -> {
122122
int d = 0;

server/src/test/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapperConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ private MapperService mapperServiceWithCustomSettings(
130130
for (var entry : customSettings.entrySet()) {
131131
settings.put(entry.getKey(), entry.getValue());
132132
}
133-
134-
return createMapperService(settings.build(), syntheticSourceMapping(mapping));
133+
settings.put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC);
134+
return createMapperService(settings.build(), mapping(mapping));
135135
}
136136

137137
protected void validateRoundTripReader(String syntheticSource, DirectoryReader reader, DirectoryReader roundTripReader)

0 commit comments

Comments
 (0)