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

Report synthetic source status in MapperBuilderContext #91400

Merged
merged 1 commit into from
Nov 8, 2022

Conversation

romseygeek
Copy link
Contributor

We currently work out whether or not a mapper should be storing additional
values for synthetic source by looking at the DocumentParserContext. However,
this value does not change for the lifetime of the mapper - it is defined by
metadata on the root mapper and is immutable - and DocumentParserContext
feels like the wrong place for this information as it holds context specific
to the document being parsed.

This commit moves synthetic source status information from DocumentParserContext
to MapperBuilderContext instead. Mappers which need this information retrieve
it at build time and hold it on final fields.

@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.6.0 labels Nov 8, 2022
@romseygeek romseygeek requested review from nik9000 and javanna November 8, 2022 12:31
@romseygeek romseygeek self-assigned this Nov 8, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Nov 8, 2022
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I like this better than having it on the various contexts.


if (metadataFieldMapper instanceof SourceFieldMapper sfm) {
isSourceSynthetic = sfm.isSynthetic();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This bit is why I didn't go this way when I was first looking at synthetic source stuff. But what you've done kind of makes sense. Metadata fields can't really care about whether or not they are synthetic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, this only applies to fields that come from the source. Which, thinking about it, some metadata fields can, like _doc_count. And looking more closely, I think _doc_count doesn't support synthetic source at all at the moment, but will just silently fail to return a value when the source is reconstructed. So we should probably do something about that...

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. I was thinking maybe metadata fields need to get a version that throws an exception if you check if synthetic source is enabled. Or maybe get an object that doesn't have that method. Not sure which is more sane.

Copy link
Member

Choose a reason for hiding this comment

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

@romseygeek and I talked in another channel and figured out that the metadata field _doc_count needs to know if synthetic source is enabled. Well, it will when I add support for synthetic _source to it. Which I should do! So I think we should merge this as is and I'll add support for doc count on top of it, messing with this code right here to make the synthetic _source-ness available to metadata mappers.

@@ -85,7 +85,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {

public <IFD extends IndexFieldData<?>> IFD getForField(String type, String fieldName, boolean docValues) {
final MappedFieldType fieldType;
final MapperBuilderContext context = MapperBuilderContext.ROOT;
final MapperBuilderContext context = MapperBuilderContext.root(false);
Copy link
Member

Choose a reason for hiding this comment

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

I was going to say this test will need to be modified to deal with synthetic source fields - but looking at it more I'm kind of confused by this test. I kind of wonder what it's for. It looks like it's testing field data abstractions without needing the whole mapped field type thing. That feels a like maybe not something worth doing. Those aren't too hard to make. We do it all the time in aggs land.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's a bit of an odd short-cut but it's used in quite a few places so I don't think it's worth touching in this PR

Copy link
Member

Choose a reason for hiding this comment

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

Right!

@@ -50,4 +55,8 @@ public String buildFullName(String name) {
}
return path + "." + name;
}

public boolean isSourceSynthetic() {
Copy link
Member

Choose a reason for hiding this comment

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

Should this throw an exception if called for metadata fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided offline to support metadata fields in a follow-up. _doc_count doesn't currently support synthetic source but it will need to.

@romseygeek romseygeek merged commit 41ab45a into elastic:main Nov 8, 2022
@romseygeek romseygeek deleted the mappercontext/synthetic branch November 8, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants