0
0
Fork 0

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:
abhinavdangeti 2018-01-29 17:09:18 -08:00
parent 5d1a2b0ad7
commit 6451c8c37f
2 changed files with 48 additions and 20 deletions

View File

@ -504,7 +504,7 @@ func (dm *DocumentMapping) processProperty(property interface{}, path []string,
} }
dm.walkDocument(property, path, indexes, context) dm.walkDocument(property, path, indexes, context)
} }
case reflect.Map: case reflect.Map, reflect.Slice:
if subDocMapping != nil { if subDocMapping != nil {
for _, fieldMapping := range subDocMapping.Fields { for _, fieldMapping := range subDocMapping.Fields {
if fieldMapping.Type == "geopoint" { if fieldMapping.Type == "geopoint" {

View File

@ -869,19 +869,46 @@ func TestMappingForGeo(t *testing.T) {
mapping := NewIndexMapping() mapping := NewIndexMapping()
mapping.DefaultMapping = thingMapping mapping.DefaultMapping = thingMapping
x := struct { geopoints := []interface{}{}
// geopoint as a struct
geopoints = append(geopoints, struct {
Name string `json:"name"` Name string `json:"name"`
Location *Location `json:"location"` Location *Location `json:"location"`
}{ }{
Name: "marty", Name: "struct",
Location: &Location{ Location: &Location{
Lon: -180, Lon: -180,
Lat: -90, Lat: -90,
}, },
} })
doc := document.NewDocument("1") // geopoint as a map
err := mapping.MapDocument(doc, x) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -901,6 +928,7 @@ func TestMappingForGeo(t *testing.T) {
if !foundGeo { if !foundGeo {
t.Errorf("expected to find geo point, did not") t.Errorf("expected to find geo point, did not")
} }
}
} }
type textMarshalable struct { type textMarshalable struct {