Skip to content

Conversation

@tballison
Copy link
Contributor

@tballison tballison commented Jan 29, 2026

Wrap source for mutability to allow updating with _inference_fields.

Fixes #141075

Is related to: #136545

@elasticsearchmachine elasticsearchmachine added v9.4.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Jan 29, 2026
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't sure if I wanted to create a new class/spin up a new cluster for this one simple test. If there's a better home for the test, let me know.

@tballison tballison added the >bug label Jan 29, 2026
@tballison tballison requested a review from Mikep86 January 29, 2026 17:35
@tballison tballison changed the title issue #141075 -- enable retrieval of only the _inference_fields from … Enable retrieval of only the _inference_fields from semantic_text Jan 29, 2026
@tballison tballison added Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch :Search Relevance/Search Catch all for Search Relevance and removed external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch labels Jan 29, 2026
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

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

Nice start! A few things to close this out:

  • Can you add a similar YAML test to 30_semantic_text_inference_bwc.yml? This is the file for testing against the old semantic_text format. In this case, setting _source_includes=_inference_fields should have no effect. We should check it doesn't cause an error though, because that was a bug we fixed previously (see this test)
  • We should investigate ways to test the changes to SearchBasedChangesSnapshot.
  • Can you update the PR title and changelog to be more specific? This bug fixes retrieving _inference_fields via _source_includes. There are other ways of getting _inference_fields that work fine.

Comment on lines 234 to 236
var newSource = new HashMap<>(originalSource.source());
newSource.put(InferenceMetadataFieldsMapper.NAME, values.get(0));
return Source.fromMap(newSource, originalSource.sourceContentType());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch here! I wonder how we test this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I investigated how to test this and the short version is this path is already tested by SemanticInferenceMetadataFieldsRecoveryTests. I think we got lucky that the test works because originalSource just happens to store source in a mutable map. But we can't count on that always being the case, so we should keep this change.

@jimczi WDYT?

@tballison tballison changed the title Enable retrieval of only the _inference_fields from semantic_text Fixes bug that prevented retrieving _inference_fields via _source_includes Jan 30, 2026
@tballison
Copy link
Contributor Author

@elasticmachine update branch

@tballison tballison marked this pull request as ready for review February 3, 2026 16:30
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Feb 3, 2026
@elasticsearchmachine
Copy link
Collaborator

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

@tballison tballison changed the title Fixes bug that prevented retrieving _inference_fields via _source_includes Improve mutability handling of Source#source()'s map Feb 3, 2026
@tballison tballison merged commit ef4ef50 into elastic:main Feb 3, 2026
35 checks passed
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Feb 4, 2026
spinscale pushed a commit to spinscale/elasticsearch that referenced this pull request Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET document source with _source_includes=_inference_fields returns 500 error due to UnsupportedOperationException

5 participants