Skip to content

Commit 41c319c

Browse files
committed
improving tests and removing redundant code
1 parent 27edf77 commit 41c319c

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

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

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,17 +1758,17 @@ setup:
17581758
name: '*'
17591759
ignore: 404
17601760

1761-
# We create the index no-template-index with an implicit mapping that has a num field with type long:
1761+
# We create the index no-template-index with an implicit mapping that has a foo field with type long:
17621762
- do:
17631763
bulk:
17641764
refresh: true
17651765
body:
17661766
- '{"index": {"_index": "no-template-index"}}'
1767-
- '{"num": 3}'
1767+
- '{"foo": 3}'
17681768

17691769
# Now we make sure that the existing mapping is taken into account when we simulate with a mapping_addition. Since
1770-
# the pre-existing mapping has num mapped as a long, this ought to fail with a document_parsing_exception because
1771-
# we are attempting to write a boolean num.
1770+
# the pre-existing mapping has foo mapped as a long, this ought to fail with a document_parsing_exception because
1771+
# we are attempting to write a boolean foo.
17721772
- do:
17731773
headers:
17741774
Content-Type: application/json
@@ -1783,7 +1783,7 @@ setup:
17831783
"_source": {
17841784
"@timestamp": "2025-07-25T09:06:06.929Z",
17851785
"is_valid": true,
1786-
"num": true
1786+
"foo": true
17871787
}
17881788
}
17891789
],
@@ -1797,14 +1797,59 @@ setup:
17971797
}
17981798
- length: { docs: 1 }
17991799
- match: { docs.0.doc._index: "no-template-index" }
1800-
- match: { docs.0.doc._source.num: true }
1800+
- match: { docs.0.doc._source.foo: true }
1801+
- match: { docs.0.doc._source.is_valid: true }
1802+
- match: { docs.0.doc.error.type: "document_parsing_exception" }
1803+
1804+
# Now we add a template for this index.
1805+
- do:
1806+
indices.put_template:
1807+
name: my-template-1
1808+
body:
1809+
index_patterns: no-template-index
1810+
mappings:
1811+
properties:
1812+
foo:
1813+
type: boolean
1814+
1815+
# And we still expect the index's mapping to be used rather than the template:
1816+
- do:
1817+
headers:
1818+
Content-Type: application/json
1819+
simulate.ingest:
1820+
index: no-template-index
1821+
body: >
1822+
{
1823+
"docs": [
1824+
{
1825+
"_id": "test-id",
1826+
"_index": "no-template-index",
1827+
"_source": {
1828+
"@timestamp": "2025-07-25T09:06:06.929Z",
1829+
"is_valid": true,
1830+
"foo": true
1831+
}
1832+
}
1833+
],
1834+
"mapping_addition": {
1835+
"properties": {
1836+
"is_valid": {
1837+
"type": "boolean"
1838+
}
1839+
}
1840+
}
1841+
}
1842+
- length: { docs: 1 }
1843+
- match: { docs.0.doc._index: "no-template-index" }
1844+
- match: { docs.0.doc._source.foo: true }
18011845
- match: { docs.0.doc._source.is_valid: true }
18021846
- match: { docs.0.doc.error.type: "document_parsing_exception" }
18031847

18041848
---
18051849
"Test ingest simulate with mapping addition for data streams when write index has different mapping":
1806-
# In this test, we make sure that when the index template is a data stream template, simulate ingest works the same whether the data
1807-
# stream has been created or not -- either way, we expect it to use the template rather than the data stream / index mappings and settings.
1850+
# In this test, we make sure that when a data stream's write index has a mapping that is different from the mapping
1851+
# in its template, and a mapping_override is given, then the mapping_override is applied to the mapping of the write
1852+
# index rather than the mapping of the template.
18081853

18091854
- skip:
18101855
features:

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ private Tuple<Collection<String>, Exception> validateMappings(
198198
Collection<String> ignoredFields = List.of();
199199
IndexAbstraction indexAbstraction = project.getIndicesLookup().get(request.index());
200200
try {
201-
if (indexAbstraction != null
202-
&& componentTemplateSubstitutions.isEmpty()
203-
&& indexTemplateSubstitutions.isEmpty()) {
201+
if (indexAbstraction != null && componentTemplateSubstitutions.isEmpty() && indexTemplateSubstitutions.isEmpty()) {
204202
/*
205203
* In this case the index exists and we don't have any template overrides. So we can just merge the mappingAddition (which
206204
* might not exist) into the existing index mapping.
@@ -281,15 +279,6 @@ private Tuple<Collection<String>, Exception> validateMappings(
281279
);
282280
final CompressedXContent combinedMappings = mergeMappings(new CompressedXContent(mappingsMap), mappingAddition);
283281
ignoredFields = validateUpdatedMappings(null, combinedMappings, request, sourceToParse);
284-
} else if (indexAbstraction != null && mappingAddition.isEmpty() == false) {
285-
/*
286-
* The index matched no templates of any kind, including the substitutions. But it might have a mapping. So we
287-
* merge in the mapping addition if it exists, and validate.
288-
*/
289-
MappingMetadata mappingFromIndex = project.index(indexAbstraction.getName()).mapping();
290-
CompressedXContent currentIndexCompressedXContent = mappingFromIndex == null ? null : mappingFromIndex.source();
291-
CompressedXContent combinedMappings = mergeMappings(currentIndexCompressedXContent, mappingAddition);
292-
ignoredFields = validateUpdatedMappings(null, combinedMappings, request, sourceToParse);
293282
} else {
294283
/*
295284
* The index matched no templates and had no mapping of its own. If there were component template substitutions
@@ -330,6 +319,7 @@ private Collection<String> validateUpdatedMappings(
330319
final IndexMetadata originalIndexMetadata = originalIndexMetadataBuilder.build();
331320
return validateUpdatedMappingsFromIndexMetadata(originalIndexMetadata, updatedMappings, request, sourceToParse);
332321
}
322+
333323
private Collection<String> validateUpdatedMappingsFromIndexMetadata(
334324
IndexMetadata originalIndexMetadata,
335325
@Nullable CompressedXContent updatedMappings,

0 commit comments

Comments
 (0)