Skip to content

Commit

Permalink
apply mapping for slices of structs
Browse files Browse the repository at this point in the history
  • Loading branch information
nwolff committed Jun 4, 2014
1 parent 6d61939 commit 0860405
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions indices/putMapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func getProperties(t reflect.Type, prop map[string]interface{}) {
if tag == "" {

// We are looking for tags on any nested struct, independently of
// whether the field is a struct or a pointer to struct.
// whether the field is a struct, a pointer to struct, or a slice of structs
targetType := field.Type
if field.Type.Kind() == reflect.Ptr {
if targetType.Kind() == reflect.Ptr ||
targetType.Kind() == reflect.Slice {
targetType = field.Type.Elem()
}

Expand Down
12 changes: 9 additions & 3 deletions indices/putMapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ type TestStruct struct {
unexported string
JsonOmitEmpty string `json:"jsonOmitEmpty,omitempty" elastic:"type:string"`
Embedded
Nested NestedStruct `json:"nested"`
NestedP *NestedStruct `json:"pointer_to_nested"`
MultiAnalyze string `json:"multi_analyze"`
Nested NestedStruct `json:"nested"`
NestedP *NestedStruct `json:"pointer_to_nested"`
NestedS []NestedStruct `json:"slice_of_nested"`
MultiAnalyze string `json:"multi_analyze"`
}

type Embedded struct {
Expand Down Expand Up @@ -111,6 +112,11 @@ func TestPutMapping(t *testing.T) {
"nestedField": {"type": "date"},
},
},
"slice_of_nested": map[string]map[string]map[string]string{
"properties": {
"nestedField": {"type": "date"},
},
},
},
})

Expand Down

0 comments on commit 0860405

Please sign in to comment.