From bd9e0d627ad3aa6ba1f26382272188679e416e2d Mon Sep 17 00:00:00 2001 From: Alain Lefebvre Date: Sat, 21 Jan 2023 15:27:50 -0500 Subject: [PATCH] Updated conditional statement to exclude counting field when the type field is set to object as it will be counted in the recursion case --- collector/indices_mappings.go | 6 ++++-- collector/indices_mappings_test.go | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/collector/indices_mappings.go b/collector/indices_mappings.go index 40e442ca..df2d77b7 100644 --- a/collector/indices_mappings.go +++ b/collector/indices_mappings.go @@ -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 diff --git a/collector/indices_mappings_test.go b/collector/indices_mappings_test.go index ff899ceb..7031ada2 100644 --- a/collector/indices_mappings_test.go +++ b/collector/indices_mappings_test.go @@ -170,6 +170,7 @@ func TestIndexMappingFieldCount(t *testing.T) { "mappings": { "properties": { "data": { + "type": "object", "properties": { "field1": { "type": "text",