Skip to content

Commit

Permalink
name cleanup: replaced 'nested' with 'inner', nested (object) has a d…
Browse files Browse the repository at this point in the history
…ifferent meaning in elasticsearch
  • Loading branch information
mikosik committed Oct 30, 2014
1 parent dde6e56 commit 5c37d6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/indicesputmapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func getProperties(t reflect.Type, prop map[string]interface{}) {
tag := field.Tag.Get("elastic")
if tag == "" {

// We are looking for tags on any nested struct, independently of
// We are looking for tags on any inner struct, independently of
// whether the field is a struct, a pointer to struct, or a slice of structs
targetType := field.Type
if targetType.Kind() == reflect.Ptr ||
Expand All @@ -97,10 +97,10 @@ func getProperties(t reflect.Type, prop map[string]interface{}) {
if field.Anonymous {
getProperties(targetType, prop)
} else {
nestedProp := make(map[string]interface{})
getProperties(targetType, nestedProp)
innerStructProp := make(map[string]interface{})
getProperties(targetType, innerStructProp)
prop[name] = map[string]interface{}{
"properties": nestedProp,
"properties": innerStructProp,
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions lib/indicesputmapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ type TestStruct struct {
unexported string
JsonOmitEmpty string `json:"jsonOmitEmpty,omitempty" elastic:"type:string"`
Embedded
Nested NestedStruct `json:"nested"`
NestedP *NestedStruct `json:"pointer_to_nested"`
NestedS []NestedStruct `json:"slice_of_nested"`
MultiAnalyze string `json:"multi_analyze"`
Inner InnerStruct `json:"inner"`
InnerP *InnerStruct `json:"pointer_to_inner"`
InnerS []InnerStruct `json:"slice_of_inner"`
MultiAnalyze string `json:"multi_analyze"`
}

type Embedded struct {
EmbeddedField string `json:"embeddedField" elastic:"type:string"`
}

type NestedStruct struct {
NestedField string `json:"nestedField" elastic:"type:date"`
type InnerStruct struct {
InnerField string `json:"innerField" elastic:"type:date"`
}

func TestPutMapping(t *testing.T) {
Expand Down Expand Up @@ -104,19 +104,19 @@ func TestPutMapping(t *testing.T) {
"ma_notanalyzed": {"type": "string", "index": "not_analyzed"},
},
},
"nested": map[string]map[string]map[string]string{
"inner": map[string]map[string]map[string]string{
"properties": {
"nestedField": {"type": "date"},
"innerField": {"type": "date"},
},
},
"pointer_to_nested": map[string]map[string]map[string]string{
"pointer_to_inner": map[string]map[string]map[string]string{
"properties": {
"nestedField": {"type": "date"},
"innerField": {"type": "date"},
},
},
"slice_of_nested": map[string]map[string]map[string]string{
"slice_of_inner": map[string]map[string]map[string]string{
"properties": {
"nestedField": {"type": "date"},
"innerField": {"type": "date"},
},
},
},
Expand Down

0 comments on commit 5c37d6c

Please sign in to comment.