MB-26396: Handling documents with geopoints in slice format
+ The issue lies with parsing documents containing a geopoint in slice format - which wasn't handled. + Unit test that verifies the fix.
This commit is contained in:
parent
5d1a2b0ad7
commit
6451c8c37f
|
@ -504,7 +504,7 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
|
|||
}
|
||||
dm.walkDocument(property, path, indexes, context)
|
||||
}
|
||||
case reflect.Map:
|
||||
case reflect.Map, reflect.Slice:
|
||||
if subDocMapping != nil {
|
||||
for _, fieldMapping := range subDocMapping.Fields {
|
||||
if fieldMapping.Type == "geopoint" {
|
||||
|
|
|
@ -869,19 +869,46 @@ func TestMappingForGeo(t *testing.T) {
|
|||
mapping := NewIndexMapping()
|
||||
mapping.DefaultMapping = thingMapping
|
||||
|
||||
x := struct {
|
||||
geopoints := []interface{}{}
|
||||
|
||||
// geopoint as a struct
|
||||
geopoints = append(geopoints, struct {
|
||||
Name string `json:"name"`
|
||||
Location *Location `json:"location"`
|
||||
}{
|
||||
Name: "marty",
|
||||
Name: "struct",
|
||||
Location: &Location{
|
||||
Lon: -180,
|
||||
Lat: -90,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
doc := document.NewDocument("1")
|
||||
err := mapping.MapDocument(doc, x)
|
||||
// geopoint as a map
|
||||
geopoints = append(geopoints, struct {
|
||||
Name string `json:"name"`
|
||||
Location map[string]interface{} `json:"location"`
|
||||
}{
|
||||
Name: "map",
|
||||
Location: map[string]interface{}{
|
||||
"lon": -180,
|
||||
"lat": -90,
|
||||
},
|
||||
})
|
||||
|
||||
// geopoint as a slice
|
||||
geopoints = append(geopoints, struct {
|
||||
Name string `json:"name"`
|
||||
Location []interface{} `json:"location"`
|
||||
}{
|
||||
Name: "slice",
|
||||
Location: []interface{}{
|
||||
-180, -90,
|
||||
},
|
||||
})
|
||||
|
||||
for i, geopoint := range geopoints {
|
||||
doc := document.NewDocument(string(i))
|
||||
err := mapping.MapDocument(doc, geopoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -901,6 +928,7 @@ func TestMappingForGeo(t *testing.T) {
|
|||
if !foundGeo {
|
||||
t.Errorf("expected to find geo point, did not")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type textMarshalable struct {
|
||||
|
|
Loading…
Reference in New Issue