Skip to content

Semantic field - generalize & improve field mapper unit tests#155003

Open
Mikep86 wants to merge 24 commits into
elastic:mainfrom
Mikep86:semantic_generalize-mapper-tests-1
Open

Semantic field - generalize & improve field mapper unit tests#155003
Mikep86 wants to merge 24 commits into
elastic:mainfrom
Mikep86:semantic_generalize-mapper-tests-1

Conversation

@Mikep86

@Mikep86 Mikep86 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

More iterations on semantic and semantic_text field mapper unit test generalizations & improvements. This is (more) groundwork for migrating the tests in SemanticTextFieldMapperTests to AbstractSemanticMapperTestCase, so that they can apply to both semantic and semantic_text fields.

The theme of this round was reducing code duplication and creating canonical ways to perform common actions:

  • assertSemanticField improvements: Improved this in a few ways:
    • Updated method to take a model, which is used to validate the embeddings sub-mapper. Previously, the method only checked that embeddings sub-mapper configuration matched model_settings, when present. However, the embeddings sub-mapper is created eagerly, whenever the inference ID is resolvable through the model registry. In contrast, model_settings is only set after first document ingest. This change materially improves test coverage by confirming that the embeddings sub-mapper is created and configured correctly, independent of model_settings.
    • Related to the point above, validate model_settings against the passed-in model.
    • Updated the method to compute the expected default index options when the model is provided and explicit expected index options are not. Previously, this method computed partial expected default index options, making it hard to reason about what index options needed to be passed. In practice, this meant that default index option computation was pushed to the caller, adding complexity and duplicated logic. Much of this complexity has now been abstracted away in assertSemanticField, and it is clearer how to use the method.
  • Migrated almost all mapping construction to the semanticMapping helper methods.
  • Removed many helper methods with either narrow scope or overlap with more general helper methods.
  • Removed complex and fiddly index version restrictions in some tests. These restrictions were created by default index option calculation (and weren't really necessary in the first place), which has now moved to assertSemanticField.

The net result is more test coverage with fewer lines of code, and a cleaner base to use to migrate tests to AbstractSemanticMapperTestCase. Those migrations will start with the next follow-up PR 🚀

Relates to #146592

@Mikep86
Mikep86 requested review from a team, kkharbas and tballison July 24, 2026 20:31
@Mikep86 Mikep86 added >test Issues or PRs that are addressing/adding tests :Search Relevance/Search Catch all for Search Relevance v9.6.0 labels Jul 24, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch >test Issues or PRs that are addressing/adding tests v9.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants