Skip to content

Commit

Permalink
Updated conditional statement to exclude counting field when the type…
Browse files Browse the repository at this point in the history
… field is set to object as it will be counted in the recursion case
  • Loading branch information
hartfordfive committed Jan 21, 2023
1 parent 3951ea2 commit bd9e0d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions collector/indices_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ func NewIndicesMappings(logger log.Logger, client *http.Client, url *url.URL) *I
func countFieldsRecursive(properties IndexMappingProperties, fieldCounter float64) float64 {
// iterate over all properties
for _, property := range properties {
if property.Type != nil {
// property has a type set - counts as a field

if property.Type != nil && *property.Type != "object" {
// property has a type set - counts as a field unless the value is object
// as the recursion below will handle counting that
fieldCounter++

// iterate over all fields of that property
Expand Down
1 change: 1 addition & 0 deletions collector/indices_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestIndexMappingFieldCount(t *testing.T) {
"mappings": {
"properties": {
"data": {
"type": "object",
"properties": {
"field1": {
"type": "text",
Expand Down

0 comments on commit bd9e0d6

Please sign in to comment.