Skip to content

Conversation

masseyke
Copy link
Member

This fixes a bug described at #131608 (comment). The problem is that if an index exists and a mapping_addition is given, we ignore the mapping from the index and instead use the mapping from the index's matching template if it exists (otherwise the index's mapping is used).

@masseyke masseyke added >bug :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP v9.1.0 v9.2.0 v8.19.1 v9.0.5 labels Jul 29, 2025
@masseyke masseyke marked this pull request as draft July 29, 2025 18:43
@elasticsearchmachine
Copy link
Collaborator

Hi @masseyke, I've created a changelog YAML for you.

@masseyke masseyke added the auto-backport Automatically create backport pull requests when merged label Jul 30, 2025
@masseyke masseyke requested a review from Copilot July 30, 2025 15:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the simulate ingest API where when an index exists and a mapping_addition is provided, the API incorrectly uses the mapping from the index's matching template instead of the actual index mapping. The fix ensures that the existing index mapping is always used as the base when merging with mapping_addition.

Key changes:

  • Simplified the condition check to always use existing index mapping when no template substitutions are present
  • Removed duplicate code path that incorrectly handled mapping addition for existing indices
  • Added comprehensive test coverage for both regular indices and data streams

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
TransportSimulateBulkAction.java Main fix - simplified logic to always use existing index mapping when available, removed duplicate handling code
80_ingest_simulate.yml Added extensive test cases covering the bug scenarios for both regular indices and data streams
132101.yaml Added changelog entry documenting the bug fix

@masseyke masseyke marked this pull request as ready for review July 30, 2025 17:26
@masseyke masseyke requested a review from dakrone July 30, 2025 17:26
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine elasticsearchmachine added the Team:Data Management Meta label for data/management team label Jul 30, 2025
Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the comments in the yaml tests, they're nice to have to follow the test.

Comment on lines 207 to 208
CompressedXContent mappings = imd.mapping() == null ? null : imd.mapping().source();
CompressedXContent mergedMappings = mappingAddition == null ? null : mergeMappings(mappings, mappingAddition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These … == null ? null : … are calling out for Optional.map() :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha yeah I thought about doing that but then didn't (for reasons I don't remember). I'll do that now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, because mergeMappings throws a checked exception, and dealing with that checked exception makes the code far more complicated than just the null checks. I'll change the first line though.

@masseyke masseyke merged commit 593f48f into elastic:main Jul 30, 2025
32 of 33 checks passed
@masseyke masseyke deleted the fix/simulate-ingest-mapping-addition branch July 30, 2025 20:03
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.1
8.19 Commit could not be cherrypicked due to conflicts
9.0 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 132101

@masseyke
Copy link
Member Author

💔 Some backports could not be created

Status Branch Result
9.0
8.19 An unhandled error occurred. Please see the logs for details

Manual backport

To create the backport manually run:

backport --pr 132101

Questions ?

Please refer to the Backport tool documentation

masseyke added a commit to masseyke/elasticsearch that referenced this pull request Jul 30, 2025
… is given (elastic#132101)

(cherry picked from commit 593f48f)

# Conflicts:
#	server/src/main/java/org/elasticsearch/action/bulk/TransportSimulateBulkAction.java
@masseyke
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.19

Questions ?

Please refer to the Backport tool documentation

masseyke added a commit to masseyke/elasticsearch that referenced this pull request Jul 30, 2025
… is given (elastic#132101)

(cherry picked from commit 593f48f)

# Conflicts:
#	server/src/main/java/org/elasticsearch/action/bulk/TransportSimulateBulkAction.java
elasticsearchmachine pushed a commit that referenced this pull request Jul 30, 2025
… is given (#132101) (#132216)

(cherry picked from commit 593f48f)

# Conflicts:
#	server/src/main/java/org/elasticsearch/action/bulk/TransportSimulateBulkAction.java
afoucret pushed a commit to afoucret/elasticsearch that referenced this pull request Jul 31, 2025
smalyshev pushed a commit to smalyshev/elasticsearch that referenced this pull request Jul 31, 2025
elasticsearchmachine pushed a commit that referenced this pull request Aug 1, 2025
… is given (#132101) (#132217)

(cherry picked from commit 593f48f)

# Conflicts:
#	server/src/main/java/org/elasticsearch/action/bulk/TransportSimulateBulkAction.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged backport pending >bug :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP Team:Data Management Meta label for data/management team v8.19.1 v9.0.5 v9.1.0 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants