-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Add NestedPathFieldMapper to store nested path information #51100
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
Add NestedPathFieldMapper to store nested path information #51100
Conversation
Pinging @elastic/es-search (:Search/Mapping) |
Pinging @elastic/es-distributed (:Distributed/CRUD) |
Note: this supersedes #50312, which removed the type field entirely; this defers that removal to a later commit |
…ng updates due to the _type field being overloaded
@elasticmachine run elasticsearch-ci/2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a first pass and added some comments. Overall it looks good to me.
|
||
@Override | ||
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) { | ||
Function<MapperService, String> typeFunction = mapperService -> mapperService.documentMapper().type(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we disallow fielddata on this field ? It's an implementation details and I am not sure that we want to expose it in aggs or sorting ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe keep it only for indices created before 8 to handle bwc ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it - indices created before 8 still use TypeFieldMapper, so BWC is handled that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed 7ea0da8
@@ -157,6 +158,7 @@ public IndicesModule(List<MapperPlugin> mapperPlugins) { | |||
builtInMetadataMappers.put(IndexFieldMapper.NAME, new IndexFieldMapper.TypeParser()); | |||
builtInMetadataMappers.put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser()); | |||
builtInMetadataMappers.put(TypeFieldMapper.NAME, new TypeFieldMapper.TypeParser()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you switch to the NestedPathFieldMapper.TypeParser
in this pr since you handle bwc in the new field type ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may be able to in future, but I think we need to keep TypeFieldMapper around for the moment because it's still used for type queries, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I was confused because there are some logic to handle bwc in NestedPathFieldMapper.
this.nestedTypePathAsString = "__" + fullPath; | ||
this.nestedTypePathAsBytes = new BytesRef(nestedTypePathAsString); | ||
this.nestedTypeFilter = new TermQuery(new Term(TypeFieldMapper.NAME, nestedTypePathAsBytes)); | ||
this.nestedTypePath = "__" + fullPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For indices created in v8 we don't need to add any prefix since we use a dedicated field ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ I pushed 7ea0da8
@@ -157,6 +158,7 @@ public IndicesModule(List<MapperPlugin> mapperPlugins) { | |||
builtInMetadataMappers.put(IndexFieldMapper.NAME, new IndexFieldMapper.TypeParser()); | |||
builtInMetadataMappers.put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser()); | |||
builtInMetadataMappers.put(TypeFieldMapper.NAME, new TypeFieldMapper.TypeParser()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I was confused because there are some logic to handle bwc in NestedPathFieldMapper.
fields.add(new Field(fieldType().name(), MapperService.SINGLE_MAPPING_NAME, fieldType())); | ||
if (fieldType().hasDocValues()) { | ||
fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(MapperService.SINGLE_MAPPING_NAME))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to index root document in this field. We use the nested path to find nested documents but we don't use this field to detect root documents so this indexing would be redundant ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ I pushed 7ea0da8
@elasticmachine update branch |
@elasticmachine run elasticsearch-ci/2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some minor comments, LGTM otherwise.
@@ -118,7 +118,7 @@ | |||
//TODO this needs to be cleaned up: _timestamp and _ttl are not supported anymore, _field_names, _seq_no, _version and _source are | |||
//also missing, not sure if on purpose. See IndicesModule#getMetadataMappers | |||
private static final String[] SORTED_META_FIELDS = new String[]{ | |||
"_id", IgnoredFieldMapper.NAME, "_index", "_routing", "_size", "_timestamp", "_ttl", "_type" | |||
"_id", IgnoredFieldMapper.NAME, "_index", "_routing", "_size", "_timestamp", "_ttl", "_type", "_nested_path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to preserve the sort order ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++, will fix. I had a look at fixing the TODO above, but it's not all that straightforward unfortunately.
server/src/main/java/org/elasticsearch/index/mapper/NestedPathFieldMapper.java
Show resolved
Hide resolved
…apper' into types-removal/nested-field-mapper
Currently nested documents repurpose the
_type
field to store their nested paths.This commit adds a dedicated
_nested_path
field instead, which decouples thisinformation from types and will allow the removal of the
_type
field entirely furtherdown the line. To preserve backwards compatibility, references to this field are
mediated via methods that take an index settings object, and indexes created before
8x still use the
_type
field.Relates to #41059
Closes #24362