Skip to content

Conversation

@jimczi
Copy link
Contributor

@jimczi jimczi commented Oct 3, 2025

The inference fields is automatically retrieved when exclude_vectors is set to false. In this change, we apply the source exclude early, in case the _inference_fields is removed, to avoid loading it entirely. We also protect against immutable map when adding the _inference_fields in _source since we cannot ensure that the map is always mutable.

Example stack trace:

Failed to execute phase [fetch], all shards failed; shardFailures {[<id>][<index>][0]: org.elasticsearch.transport.RemoteTransportException: [<node>][<ip-address>:9300][indices:data/read/search[phase/fetch/id]]
Caused by: org.elasticsearch.search.fetch.FetchPhaseExecutionException: Fetch Failed [Error running fetch phase for doc [1]]
	at [email protected]/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:109)
	at [email protected]/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:248)
	at [email protected]/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:91)
	at [email protected]/org.elasticsearch.search.SearchService.lambda$executeFetchPhase$16(SearchService.java:1212)
	at [email protected]/org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:79)
	at [email protected]/org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:76)
	at [email protected]/org.elasticsearch.action.ActionRunnable$4.doRun(ActionRunnable.java:101)
	at [email protected]/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)
	at [email protected]/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:35)
	at [email protected]/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:1067)
	at [email protected]/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:27)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
	at java.base/java.lang.Thread.run(Thread.java:1474)
Caused by: java.lang.UnsupportedOperationException
	at java.base/java.util.ImmutableCollections.uoe(ImmutableCollections.java:159)
	at java.base/java.util.ImmutableCollections$AbstractImmutableMap.put(ImmutableCollections.java:1318)
	at [email protected]/org.elasticsearch.search.fetch.subphase.FetchSourcePhase$1.replaceInferenceMetadataFields(FetchSourcePhase.java:102)
	at [email protected]/org.elasticsearch.search.fetch.subphase.FetchSourcePhase$1.hitExecute(FetchSourcePhase.java:83)
	at [email protected]/org.elasticsearch.search.fetch.subphase.FetchSourcePhase$1.process(FetchSourcePhase.java:58)
	at [email protected]/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:231)
	at [email protected]/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:90)
	... 13 more

The inference fields is automatically retrieved when `exclude_vectors` is set to false.
In this change, we apply the source exclude early, in case the _inference_fields is removed, to avoid loading it entirely.
We also protect against immutable map when adding the _inference_fields in _source since we cannot ensure that the map is always mutable.
@jimczi jimczi requested a review from pmpailis October 3, 2025 09:48
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Oct 3, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@pmpailis pmpailis left a comment

Choose a reason for hiding this comment

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

LGTM! Should we also update docs clarifying how exclude_vectors interacts with include/exclude?

@jimczi jimczi added the auto-backport Automatically create backport pull requests when merged label Oct 3, 2025
@jimczi jimczi merged commit 72f2bcb into elastic:main Oct 3, 2025
34 checks passed
@jimczi jimczi deleted the inference_fields_rehydratation branch October 3, 2025 16:57
@jimczi
Copy link
Contributor Author

jimczi commented Oct 3, 2025

Should we also update docs clarifying how exclude_vectors interacts with include/exclude?

I'll open a follow up pr, thanks

@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
9.2

elasticsearchmachine pushed a commit that referenced this pull request Oct 3, 2025
…35897) (#135954)

The inference fields is automatically retrieved when `exclude_vectors` is set to false.
In this change, we apply the source exclude early, in case the _inference_fields is removed, to avoid loading it entirely.
We also protect against immutable map when adding the _inference_fields in _source since we cannot ensure that the map is always mutable.
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 >bug :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.2.1 v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants