Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate mapper builder context flags across nested mapper builder context creation #109963

Merged

Conversation

javanna
Copy link
Member

@javanna javanna commented Jun 20, 2024

MapperBuilderContext includes information about whether synthetic source is configured, we are in a data streams and there are dimensions. This info is currently not propagated across the constructor of NestedMapperBuilderContext, which means that the builder context for the nested type receives hardcoded (false) info. This commit fixes that.

One symptom of this, due to not propagating the info about whether synthetic source is configured, is that numeric fields that have ignore_malformed set to true, mapped under a nested type, will cause shard failures whenever a document with ignored values is retrieved in the fetch phase:

[2024-06-21T19:31:11,839][WARN ][o.e.a.s.TransportSearchAction] [node_s0] TransportSearchAction shard failure (partial results response)
org.elasticsearch.action.search.ShardSearchFailure: null
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:562) ~[main/:?]
	at org.elasticsearch.action.search.CountedCollector.onFailure(CountedCollector.java:57) ~[main/:?]
	at org.elasticsearch.action.search.FetchSearchPhase$2.onFailure(FetchSearchPhase.java:233) ~[main/:?]
	at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:53) ~[main/:?]
	at org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:672) ~[main/:?]
	at org.elasticsearch.transport.TransportService$UnregisterChildTransportResponseHandler.handleException(TransportService.java:1766) ~[main/:?]
	at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1490) ~[main/:?]
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1624) ~[main/:?]
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1599) ~[main/:?]
	at org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:44) ~[main/:?]
	at org.elasticsearch.action.support.ChannelActionListener.onFailure(ChannelActionListener.java:44) ~[main/:?]
	at org.elasticsearch.search.SearchService$2.onFailure(SearchService.java:1241) ~[main/:?]
	at org.elasticsearch.action.ActionRunnable.onFailure(ActionRunnable.java:151) ~[main/:?]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28) ~[main/:?]
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33) ~[main/:?]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:984) ~[main/:?]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26) ~[main/:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
	at java.lang.Thread.run(Thread.java:1570) ~[?:?]
Caused by: com.fasterxml.jackson.core.JsonGenerationException: Can not start an object, expecting field name (context: Object)
	at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:2849) ~[?:?]
	at com.fasterxml.jackson.core.json.JsonGeneratorImpl._reportCantWriteValueExpectName(JsonGeneratorImpl.java:262) ~[?:?]
	at com.fasterxml.jackson.core.json.UTF8JsonGenerator._verifyValueWrite(UTF8JsonGenerator.java:1179) ~[?:?]
	at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeStartObject(UTF8JsonGenerator.java:375) ~[?:?]
	at org.elasticsearch.xcontent.provider.json.JsonXContentGenerator.writeStartObject(JsonXContentGenerator.java:148) ~[?:?]
	at org.elasticsearch.xcontent.XContentBuilder.startObject(XContentBuilder.java:329) ~[elasticsearch-x-content-8.15.0-SNAPSHOT.jar:8.15.0-SNAPSHOT]
	at org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.write(SourceLoader.java:216) ~[main/:?]
	at org.elasticsearch.index.mapper.SourceLoader$Synthetic$LeafWithMetrics.write(SourceLoader.java:158) ~[main/:?]
	at org.elasticsearch.index.mapper.NestedObjectMapper$NestedSyntheticFieldLoader.write(NestedObjectMapper.java:456) ~[main/:?]
	at org.elasticsearch.index.mapper.ObjectMapper$SyntheticSourceFieldLoader.write(ObjectMapper.java:875) ~[main/:?]
	at org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.write(SourceLoader.java:214) ~[main/:?]
	at org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:181) ~[main/:?]
	at org.elasticsearch.index.mapper.SourceLoader$Synthetic$LeafWithMetrics.source(SourceLoader.java:146) ~[main/:?]
	at org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:289) ~[main/:?]
	at org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:232) ~[main/:?]
	at org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:161) ~[main/:?]
	at org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:71) ~[main/:?]
	at org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:190) ~[main/:?]
	at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:80) ~[main/:?]
	at org.elasticsearch.search.SearchService.lambda$executeFetchPhase$10(SearchService.java:907) ~[main/:?]
	at org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:78) ~[main/:?]
	at org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:75) ~[main/:?]
	at org.elasticsearch.action.ActionRunnable$4.doRun(ActionRunnable.java:100) ~[main/:?]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26) ~[main/:?]
	... 6 more
	Suppressed: java.lang.IllegalStateException: Failed to close the XContentBuilder
		at org.elasticsearch.xcontent.XContentBuilder.close(XContentBuilder.java:1281) ~[elasticsearch-x-content-8.15.0-SNAPSHOT.jar:8.15.0-SNAPSHOT]
		at org.elasticsearch.index.mapper.SourceLoader$Synthetic$SyntheticLeaf.source(SourceLoader.java:180) ~[main/:?]
		at org.elasticsearch.index.mapper.SourceLoader$Synthetic$LeafWithMetrics.source(SourceLoader.java:146) ~[main/:?]
		at org.elasticsearch.search.fetch.FetchPhase.prepareNonNestedHitContext(FetchPhase.java:289) ~[main/:?]
		at org.elasticsearch.search.fetch.FetchPhase.prepareHitContext(FetchPhase.java:232) ~[main/:?]
		at org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:161) ~[main/:?]
		at org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:71) ~[main/:?]
		at org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:190) ~[main/:?]
		at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:80) ~[main/:?]
		at org.elasticsearch.search.SearchService.lambda$executeFetchPhase$10(SearchService.java:907) ~[main/:?]
		at org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:78) ~[main/:?]
		at org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:75) ~[main/:?]
		at org.elasticsearch.action.ActionRunnable$4.doRun(ActionRunnable.java:100) ~[main/:?]
		at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26) ~[main/:?]
		at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33) ~[main/:?]
		at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:984) ~[main/:?]
		at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26) ~[main/:?]
		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
		at java.lang.Thread.run(Thread.java:1570) ~[?:?]
	Caused by: java.io.IOException: Unclosed object or array found
		at org.elasticsearch.xcontent.provider.json.JsonXContentGenerator.close(JsonXContentGenerator.java:599) ~[?:?]
		at org.elasticsearch.xcontent.XContentBuilder.close(XContentBuilder.java:1279) ~[elasticsearch-x-content-8.15.0-SNAPSHOT.jar:8.15.0-SNAPSHOT]
		... 19 more

@javanna javanna added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.15.0 labels Jun 20, 2024
@javanna javanna requested a review from martijnvg June 20, 2024 11:10
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jun 20, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

Maybe add a yaml test with a mapping that uses a nested field type, which has a sub field of type date or long with ignore_malformed enabled. Also enable index.mode=logs. Index a document with that structure and with a malformed value. Then assert that the malformed value can be retrieved from _source. I expect this to fail without this fix.

@javanna javanna requested review from a team as code owners June 21, 2024 08:47
javanna and others added 2 commits June 21, 2024 10:48
…ontext creation

MapperBuilderContext includes information about whether synthetic source is configured, we are in a data streams and there are dimensions.
This info is currently not propagated across the constructor of NestedMapperBuilderContext, which means that the builder context for the
nested type receives hardcoded (false) info. This commit fixes that.
@javanna javanna force-pushed the fix/propagate_nested_mapper_builder_context_flags branch from 280c0a6 to 58382df Compare June 21, 2024 08:48
@javanna javanna removed request for a team June 21, 2024 08:49
Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

Thanks for adding the integration test that shows how this bug breaks synthetic source.
LGTM2

@javanna
Copy link
Member Author

javanna commented Jun 21, 2024

@elasticmachine run elasticsearch-ci/part-1

@javanna javanna added v8.14.2 auto-backport Automatically create backport pull requests when merged labels Jun 21, 2024
@javanna javanna merged commit b0d9f95 into elastic:main Jun 21, 2024
15 checks passed
@javanna javanna deleted the fix/propagate_nested_mapper_builder_context_flags branch June 21, 2024 19:40
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.14 Commit could not be cherrypicked due to conflicts

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

javanna added a commit to javanna/elasticsearch that referenced this pull request Jun 24, 2024
…ontext creation (elastic#109963)

MapperBuilderContext includes information about whether synthetic source is configured, we are in a data streams and there are dimensions.
This info is currently not propagated across the constructor of NestedMapperBuilderContext, which means that the builder context for the
nested type receives hardcoded (false) info. This commit fixes that.

One symptom of this, due to not propagating the info about whether synthetic source is configured, is that numeric fields that have ignore_malformed set to true, mapped under a nested type, will cause shard failures whenever a document with ignored values is retrieved in the fetch phase
@javanna javanna removed auto-backport Automatically create backport pull requests when merged v8.14.2 labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants