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

MB-62400: Allow vector and numeric aliases for the same field #2055

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions mapping/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,33 +534,33 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
dm.walkDocument(property, path, indexes, context)
}
case reflect.Map, reflect.Slice:
var isPropertyVector bool
var isPropertyVectorInitialized bool
if subDocMapping != nil {
walkDocument := false
if subDocMapping != nil && len(subDocMapping.Fields) != 0 {
for _, fieldMapping := range subDocMapping.Fields {
switch fieldMapping.Type {
case "vector":
processed := fieldMapping.processVector(property, pathString, path,
fieldMapping.processVector(property, pathString, path,
indexes, context)
if !isPropertyVectorInitialized {
isPropertyVector = processed
isPropertyVectorInitialized = true
} else {
isPropertyVector = isPropertyVector && processed
}
Copy link
Member

Choose a reason for hiding this comment

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

@Likith101 I believe @CascadingRadium added this and my memory on this is somewhat hazy - it seems we did this to avoid having to process a vector field multiple times, I like your code proposal here which is simple and easy to follow - just want to make sure we're not inadvertently dropping any optimization here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I collaborated with @CascadingRadium on this and we made sure to preserve any existing behaviour that was present before vectors and only remove the double processing for vector fields.

case "geopoint":
fieldMapping.processGeoPoint(property, pathString, path, indexes, context)
walkDocument = true
case "IP":
ip, ok := property.(net.IP)
if ok {
fieldMapping.processIP(ip, pathString, path, indexes, context)
}
walkDocument = true
case "geoshape":
fieldMapping.processGeoShape(property, pathString, path, indexes, context)
walkDocument = true
default:
walkDocument = true
}
}
} else {
walkDocument = true
}
if !isPropertyVector {
if walkDocument {
dm.walkDocument(property, path, indexes, context)
}
case reflect.Ptr:
Expand Down
Loading