Skip to content

Commit 791cdc9

Browse files
committed
changing parameter name to merge_type
1 parent 0484138 commit 791cdc9

File tree

8 files changed

+42
-39
lines changed

8 files changed

+42
-39
lines changed

docs/changelog/132210.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pr: 132210
2-
summary: Adding a `mapping_merge_reason` parameter to the ingest simulate API
2+
summary: Adding a `merge_type` parameter to the ingest simulate API
33
area: Ingest Node
44
type: enhancement
55
issues:

qa/smoke-test-ingest-with-all-dependencies/src/yamlRestTest/resources/rest-api-spec/test/ingest/80_ingest_simulate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ setup:
19851985
headers:
19861986
Content-Type: application/json
19871987
simulate.ingest:
1988-
mapping_merge_reason: "index_template"
1988+
merge_type: "template"
19891989
body: >
19901990
{
19911991
"docs": [

rest-api-spec/src/main/resources/rest-api-spec/api/simulate.ingest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
"type":"string",
4040
"description":"The pipeline id to preprocess incoming documents with if no pipeline is given for a particular document"
4141
},
42-
"mapping_merge_reason":{
42+
"merge_type":{
4343
"type":"string",
44-
"description":"The mapping merge reason if mapping overrides are being provided in mapping_addition, index_template_substitutions, or component_template_substitutions. The allowed values are one of mapping_update or index_template. The mapping_update option merges mappings the way they would be merged into an existing index. The index_template option merges mappings the way they would be merged into a template.",
44+
"description":"The mapping merge type if mapping overrides are being provided in mapping_addition, index_template_substitutions, or component_template_substitutions. The allowed values are one of index or template. The index option merges mappings the way they would be merged into an existing index. The template option merges mappings the way they would be merged into a template.",
4545
"default": "mapping_update"
4646
}
4747
},

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static TransportVersion def(int id) {
356356
public static final TransportVersion PIPELINE_TRACKING_INFO = def(9_131_0_00);
357357
public static final TransportVersion COMPONENT_TEMPLATE_TRACKING_INFO = def(9_132_0_00);
358358
public static final TransportVersion TO_CHILD_BLOCK_JOIN_QUERY = def(9_133_0_00);
359-
public static final TransportVersion SIMULATE_INGEST_MAPPING_MERGE_REASON = def(9_134_0_00);
359+
public static final TransportVersion SIMULATE_INGEST_MAPPING_MERGE_TYPE = def(9_134_0_00);
360360

361361
/*
362362
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/action/bulk/SimulateBulkRequest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class SimulateBulkRequest extends BulkRequest {
103103
private final Map<String, Map<String, Object>> componentTemplateSubstitutions;
104104
private final Map<String, Map<String, Object>> indexTemplateSubstitutions;
105105
private final Map<String, Object> mappingAddition;
106-
private final String mappingMergeReason;
106+
private final String mappingMergeType;
107107

108108
/**
109109
* @param pipelineSubstitutions The pipeline definitions that are to be used in place of any pre-existing pipeline definitions with
@@ -120,7 +120,7 @@ public SimulateBulkRequest(
120120
Map<String, Map<String, Object>> componentTemplateSubstitutions,
121121
Map<String, Map<String, Object>> indexTemplateSubstitutions,
122122
Map<String, Object> mappingAddition,
123-
String mappingMergeReason
123+
String mappingMergeType
124124
) {
125125
super();
126126
Objects.requireNonNull(pipelineSubstitutions);
@@ -131,7 +131,7 @@ public SimulateBulkRequest(
131131
this.componentTemplateSubstitutions = componentTemplateSubstitutions;
132132
this.indexTemplateSubstitutions = indexTemplateSubstitutions;
133133
this.mappingAddition = mappingAddition;
134-
this.mappingMergeReason = mappingMergeReason;
134+
this.mappingMergeType = mappingMergeType;
135135
}
136136

137137
@SuppressWarnings("unchecked")
@@ -150,10 +150,10 @@ public SimulateBulkRequest(StreamInput in) throws IOException {
150150
} else {
151151
mappingAddition = Map.of();
152152
}
153-
if (in.getTransportVersion().onOrAfter(TransportVersions.SIMULATE_INGEST_MAPPING_MERGE_REASON)) {
154-
mappingMergeReason = in.readOptionalString();
153+
if (in.getTransportVersion().onOrAfter(TransportVersions.SIMULATE_INGEST_MAPPING_MERGE_TYPE)) {
154+
mappingMergeType = in.readOptionalString();
155155
} else {
156-
mappingMergeReason = null;
156+
mappingMergeType = null;
157157
}
158158
}
159159

@@ -168,8 +168,8 @@ public void writeTo(StreamOutput out) throws IOException {
168168
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_17_0)) {
169169
out.writeGenericValue(mappingAddition);
170170
}
171-
if (out.getTransportVersion().onOrAfter(TransportVersions.SIMULATE_INGEST_MAPPING_MERGE_REASON)) {
172-
out.writeOptionalString(mappingMergeReason);
171+
if (out.getTransportVersion().onOrAfter(TransportVersions.SIMULATE_INGEST_MAPPING_MERGE_TYPE)) {
172+
out.writeOptionalString(mappingMergeType);
173173
}
174174
}
175175

@@ -200,8 +200,8 @@ public Map<String, Object> getMappingAddition() {
200200
return mappingAddition;
201201
}
202202

203-
public String getMappingMergeReason() {
204-
return mappingMergeReason;
203+
public String getMappingMergeType() {
204+
return mappingMergeType;
205205
}
206206

207207
private static ComponentTemplate convertRawTemplateToComponentTemplate(Map<String, Object> rawTemplate) {
@@ -231,7 +231,7 @@ public BulkRequest shallowClone() {
231231
componentTemplateSubstitutions,
232232
indexTemplateSubstitutions,
233233
mappingAddition,
234-
mappingMergeReason
234+
mappingMergeType
235235
);
236236
bulkRequest.setRefreshPolicy(getRefreshPolicy());
237237
bulkRequest.waitForActiveShards(waitForActiveShards());

server/src/main/java/org/elasticsearch/action/bulk/TransportSimulateBulkAction.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
import java.util.Collection;
6969
import java.util.HashMap;
7070
import java.util.List;
71-
import java.util.Locale;
7271
import java.util.Map;
7372
import java.util.Optional;
7473
import java.util.Set;
@@ -137,9 +136,7 @@ protected void doInternalExecute(
137136
Map<String, ComponentTemplate> componentTemplateSubstitutions = bulkRequest.getComponentTemplateSubstitutions();
138137
Map<String, ComposableIndexTemplate> indexTemplateSubstitutions = bulkRequest.getIndexTemplateSubstitutions();
139138
Map<String, Object> mappingAddition = ((SimulateBulkRequest) bulkRequest).getMappingAddition();
140-
MapperService.MergeReason mappingMergeReason = Optional.ofNullable(((SimulateBulkRequest) bulkRequest).getMappingMergeReason())
141-
.map(mergeReason -> MapperService.MergeReason.valueOf(mergeReason.toUpperCase(Locale.ROOT)))
142-
.orElse(MapperService.MergeReason.MAPPING_UPDATE);
139+
MapperService.MergeReason mappingMergeReason = getMergeReason(((SimulateBulkRequest) bulkRequest).getMappingMergeType());
143140
for (int i = 0; i < bulkRequest.requests.size(); i++) {
144141
DocWriteRequest<?> docRequest = bulkRequest.requests.get(i);
145142
assert docRequest instanceof IndexRequest : "TransportSimulateBulkAction should only ever be called with IndexRequests";
@@ -175,6 +172,14 @@ protected void doInternalExecute(
175172
);
176173
}
177174

175+
private MapperService.MergeReason getMergeReason(String mergeType) {
176+
return Optional.ofNullable(mergeType).map(type -> switch (type) {
177+
case "index" -> MapperService.MergeReason.MAPPING_UPDATE;
178+
case "template" -> MapperService.MergeReason.INDEX_TEMPLATE;
179+
default -> throw new IllegalArgumentException("Unsupported merge type " + mergeType);
180+
}).orElse(MapperService.MergeReason.MAPPING_UPDATE);
181+
}
182+
178183
/**
179184
* This creates a temporary index with the mappings of the index in the request, and then attempts to index the source from the request
180185
* into it. If there is a mapping exception, that exception is returned. On success the returned exception is null.

server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulateIngestAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
8585
"index_template_substitutions"
8686
);
8787
Object mappingAddition = sourceMap.remove("mapping_addition");
88-
String mappingMergeReason = request.param("mapping_merge_reason");
88+
String mappingMergeType = request.param("merge_type");
8989
SimulateBulkRequest bulkRequest = new SimulateBulkRequest(
9090
pipelineSubstitutions == null ? Map.of() : pipelineSubstitutions,
9191
componentTemplateSubstitutions == null ? Map.of() : componentTemplateSubstitutions,
9292
indexTemplateSubstitutions == null ? Map.of() : indexTemplateSubstitutions,
9393
mappingAddition == null ? Map.of() : Map.of("_doc", mappingAddition),
94-
mappingMergeReason
94+
mappingMergeType
9595
);
9696
BytesReference transformedData = convertToBulkRequestXContentBytes(sourceMap);
9797
bulkRequest.add(

server/src/test/java/org/elasticsearch/action/bulk/SimulateBulkRequestTests.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
1515
import org.elasticsearch.common.bytes.BytesArray;
1616
import org.elasticsearch.common.xcontent.XContentHelper;
17-
import org.elasticsearch.index.mapper.MapperService;
1817
import org.elasticsearch.test.ESTestCase;
1918
import org.elasticsearch.xcontent.XContentType;
2019

2120
import java.io.IOException;
2221
import java.nio.charset.StandardCharsets;
2322
import java.util.List;
24-
import java.util.Locale;
2523
import java.util.Map;
2624

2725
import static java.util.Map.entry;
@@ -36,7 +34,7 @@ public void testSerialization() throws Exception {
3634
getMapOrEmpty(getTestComponentTemplateSubstitutions()),
3735
getMapOrEmpty(getTestIndexTemplateSubstitutions()),
3836
getMapOrEmpty(getTestMappingAddition()),
39-
getTestMappingMergeReason()
37+
getTestMappingMergeType()
4038
);
4139
}
4240

@@ -56,7 +54,7 @@ public void testNullsNotAllowed() {
5654
getTestPipelineSubstitutions(),
5755
getTestComponentTemplateSubstitutions(),
5856
getTestMappingAddition(),
59-
getTestMappingMergeReason()
57+
getTestMappingMergeType()
6058
)
6159
);
6260
assertThrows(
@@ -66,7 +64,7 @@ public void testNullsNotAllowed() {
6664
null,
6765
getTestComponentTemplateSubstitutions(),
6866
getTestMappingAddition(),
69-
getTestMappingMergeReason()
67+
getTestMappingMergeType()
7068
)
7169
);
7270
assertThrows(
@@ -76,7 +74,7 @@ public void testNullsNotAllowed() {
7674
getTestPipelineSubstitutions(),
7775
null,
7876
getTestMappingAddition(),
79-
getTestMappingMergeReason()
77+
getTestMappingMergeType()
8078
)
8179
);
8280
assertThrows(
@@ -86,7 +84,7 @@ public void testNullsNotAllowed() {
8684
getTestPipelineSubstitutions(),
8785
getTestComponentTemplateSubstitutions(),
8886
null,
89-
getTestMappingMergeReason()
87+
getTestMappingMergeType()
9088
)
9189
);
9290
}
@@ -96,22 +94,22 @@ private void testSerialization(
9694
Map<String, Map<String, Object>> componentTemplateSubstitutions,
9795
Map<String, Map<String, Object>> indexTemplateSubstitutions,
9896
Map<String, Object> mappingAddition,
99-
String mappingMergeReason
97+
String mappingMergeType
10098
) throws IOException {
10199
SimulateBulkRequest simulateBulkRequest = new SimulateBulkRequest(
102100
pipelineSubstitutions,
103101
componentTemplateSubstitutions,
104102
indexTemplateSubstitutions,
105103
mappingAddition,
106-
mappingMergeReason
104+
mappingMergeType
107105
);
108106
/*
109107
* Note: SimulateBulkRequest does not implement equals or hashCode, so we can't test serialization in the usual way for a
110108
* Writable
111109
*/
112110
SimulateBulkRequest copy = copyWriteable(simulateBulkRequest, null, SimulateBulkRequest::new);
113111
assertThat(copy.getPipelineSubstitutions(), equalTo(simulateBulkRequest.getPipelineSubstitutions()));
114-
assertThat(copy.getMappingMergeReason(), equalTo(simulateBulkRequest.getMappingMergeReason()));
112+
assertThat(copy.getMappingMergeType(), equalTo(simulateBulkRequest.getMappingMergeType()));
115113
}
116114

117115
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -121,7 +119,7 @@ public void testGetComponentTemplateSubstitutions() throws IOException {
121119
Map.of(),
122120
Map.of(),
123121
Map.of(),
124-
getTestMappingMergeReason()
122+
getTestMappingMergeType()
125123
);
126124
assertThat(simulateBulkRequest.getComponentTemplateSubstitutions(), equalTo(Map.of()));
127125
String substituteComponentTemplatesString = """
@@ -161,7 +159,7 @@ public void testGetComponentTemplateSubstitutions() throws IOException {
161159
substituteComponentTemplates,
162160
Map.of(),
163161
Map.of(),
164-
getTestMappingMergeReason()
162+
getTestMappingMergeType()
165163
);
166164
Map<String, ComponentTemplate> componentTemplateSubstitutions = simulateBulkRequest.getComponentTemplateSubstitutions();
167165
assertThat(componentTemplateSubstitutions.size(), equalTo(2));
@@ -192,7 +190,7 @@ public void testGetIndexTemplateSubstitutions() throws IOException {
192190
Map.of(),
193191
Map.of(),
194192
Map.of(),
195-
getTestMappingMergeReason()
193+
getTestMappingMergeType()
196194
);
197195
assertThat(simulateBulkRequest.getIndexTemplateSubstitutions(), equalTo(Map.of()));
198196
String substituteIndexTemplatesString = """
@@ -229,7 +227,7 @@ public void testGetIndexTemplateSubstitutions() throws IOException {
229227
randomBoolean(),
230228
XContentType.JSON
231229
).v2();
232-
simulateBulkRequest = new SimulateBulkRequest(Map.of(), Map.of(), substituteIndexTemplates, Map.of(), getTestMappingMergeReason());
230+
simulateBulkRequest = new SimulateBulkRequest(Map.of(), Map.of(), substituteIndexTemplates, Map.of(), getTestMappingMergeType());
233231
Map<String, ComposableIndexTemplate> indexTemplateSubstitutions = simulateBulkRequest.getIndexTemplateSubstitutions();
234232
assertThat(indexTemplateSubstitutions.size(), equalTo(2));
235233
assertThat(
@@ -256,7 +254,7 @@ public void testShallowClone() throws IOException {
256254
getTestComponentTemplateSubstitutions(),
257255
getTestIndexTemplateSubstitutions(),
258256
getTestMappingAddition(),
259-
getTestMappingMergeReason()
257+
getTestMappingMergeType()
260258
);
261259
simulateBulkRequest.setRefreshPolicy(randomFrom(WriteRequest.RefreshPolicy.values()));
262260
simulateBulkRequest.waitForActiveShards(randomIntBetween(1, 10));
@@ -343,11 +341,11 @@ private static Map<String, Object> getTestMappingAddition() {
343341
);
344342
}
345343

346-
private static String getTestMappingMergeReason() {
344+
private static String getTestMappingMergeType() {
347345
if (randomBoolean()) {
348346
return null;
349347
} else {
350-
return randomFrom(MapperService.MergeReason.values()).toString().toLowerCase(Locale.ROOT);
348+
return randomFrom("index", "template");
351349
}
352350
}
353351
}

0 commit comments

Comments
 (0)