From 229368aef0fdabef6bd89ba199e3f79301ba4714 Mon Sep 17 00:00:00 2001 From: CascadingRadium Date: Mon, 12 Feb 2024 13:04:13 +0530 Subject: [PATCH] Do not walk document if vector is processed successfully --- mapping/document.go | 8 ++++++-- mapping/mapping_no_vectors.go | 4 ++-- mapping/mapping_vectors.go | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mapping/document.go b/mapping/document.go index 752ea3cad..5d2132577 100644 --- a/mapping/document.go +++ b/mapping/document.go @@ -532,12 +532,14 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string, dm.walkDocument(property, path, indexes, context) } case reflect.Map, reflect.Slice: + var isPropertyVector bool if subDocMapping != nil { for _, fieldMapping := range subDocMapping.Fields { switch fieldMapping.Type { case "vector": - fieldMapping.processVector(property, pathString, path, + processed := fieldMapping.processVector(property, pathString, path, indexes, context) + isPropertyVector = isPropertyVector && processed case "geopoint": fieldMapping.processGeoPoint(property, pathString, path, indexes, context) case "IP": @@ -550,7 +552,9 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string, } } } - dm.walkDocument(property, path, indexes, context) + if !isPropertyVector { + dm.walkDocument(property, path, indexes, context) + } case reflect.Ptr: if !propertyValue.IsNil() { switch property := property.(type) { diff --git a/mapping/mapping_no_vectors.go b/mapping/mapping_no_vectors.go index b5e033a62..f9f35f57c 100644 --- a/mapping/mapping_no_vectors.go +++ b/mapping/mapping_no_vectors.go @@ -22,8 +22,8 @@ func NewVectorFieldMapping() *FieldMapping { } func (fm *FieldMapping) processVector(propertyMightBeVector interface{}, - pathString string, path []string, indexes []uint64, context *walkContext) { - + pathString string, path []string, indexes []uint64, context *walkContext) bool { + return false } // ----------------------------------------------------------------------------- diff --git a/mapping/mapping_vectors.go b/mapping/mapping_vectors.go index b7c5bf147..a0b712608 100644 --- a/mapping/mapping_vectors.go +++ b/mapping/mapping_vectors.go @@ -122,11 +122,11 @@ func processVector(vecI interface{}, dims int) ([]float32, bool) { } func (fm *FieldMapping) processVector(propertyMightBeVector interface{}, - pathString string, path []string, indexes []uint64, context *walkContext) { + pathString string, path []string, indexes []uint64, context *walkContext) bool { vector, ok := processVector(propertyMightBeVector, fm.Dims) // Don't add field to document if vector is invalid if !ok { - return + return false } fieldName := getFieldName(pathString, path, fm) @@ -137,6 +137,7 @@ func (fm *FieldMapping) processVector(propertyMightBeVector interface{}, // "_all" composite field is not applicable for vector field context.excludedFromAll = append(context.excludedFromAll, fieldName) + return true } // -----------------------------------------------------------------------------