Add NestedPathFieldMapper to store nested path information#51100
Add NestedPathFieldMapper to store nested path information#51100romseygeek merged 15 commits intoelastic:masterfrom
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 |
jimczi
left a comment
There was a problem hiding this comment.
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.
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.
Maybe keep it only for indices created before 8 to handle bwc ?
There was a problem hiding this comment.
I'll remove it - indices created before 8 still use TypeFieldMapper, so BWC is handled that way
| @@ -157,6 +158,7 @@ private static Map<String, MetadataFieldMapper.TypeParser> initBuiltInMetadataMa | |||
| 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.
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.
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.
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.
For indices created in v8 we don't need to add any prefix since we use a dedicated field ?
| @@ -157,6 +158,7 @@ private static Map<String, MetadataFieldMapper.TypeParser> initBuiltInMetadataMa | |||
| 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.
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.
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 ?
|
@elasticmachine update branch |
|
@elasticmachine run elasticsearch-ci/2 |
jimczi
left a comment
There was a problem hiding this comment.
I left some minor comments, LGTM otherwise.
| //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.
I think you need to preserve the sort order ?
There was a problem hiding this comment.
++, 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
_typefield to store their nested paths.This commit adds a dedicated
_nested_pathfield instead, which decouples thisinformation from types and will allow the removal of the
_typefield 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
_typefield.Relates to #41059
Closes #24362