Repository: meilisearch/meilisearch-go

Issue:
[v1.13] Add documents database metrics to stats
*Following the [changes related to Meilisearch v1.13.0 mega issue](https://github.com/meilisearch/integration-guides/issues/314):*

## Description

Update the [`stats` object](https://www.meilisearch.com/docs/reference/api/stats#stats-object?utm_campaign=oss&utm_source=github) to include the new **documents database metrics**.

For further reference, see the related [Meilisearch engine issue](https://github.com/meilisearch/meilisearch/issues/5319).

## Specifications

- [ ] Modify the stats API to include `indexes.INDEXNAME.rawDocumentDbSize` in SDK responses
- [ ] Modify the stats API to include `indexes.INDEXNAME.avgDocumentSize` in SDK responses

Hints from issue comments:

Solution patch:
diff --git a/types.go b/types.go
index 199fd39..7e29ae8 100644
--- a/types.go
+++ b/types.go
@@ -153,6 +153,8 @@ type StatsIndex struct {
 	NumberOfDocuments         int64            `json:"numberOfDocuments"`
 	IsIndexing                bool             `json:"isIndexing"`
 	FieldDistribution         map[string]int64 `json:"fieldDistribution"`
+	RawDocumentDbSize         int64            `json:"rawDocumentDbSize"`
+	AvgDocumentSize           int64            `json:"avgDocumentSize"`
 	NumberOfEmbeddedDocuments int64            `json:"numberOfEmbeddedDocuments"`
 	NumberOfEmbeddings        int64            `json:"numberOfEmbeddings"`
 }
diff --git a/types_easyjson.go b/types_easyjson.go
index 112ce77..e768631 100644
--- a/types_easyjson.go
+++ b/types_easyjson.go
@@ -1582,6 +1582,10 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(in *jlexer.Lexer,
 				}
 				in.Delim('}')
 			}
+		case "rawDocumentDbSize":
+			out.RawDocumentDbSize = int64(in.Int64())
+		case "avgDocumentSize":
+			out.AvgDocumentSize = int64(in.Int64())
 		case "numberOfEmbeddedDocuments":
 			out.NumberOfEmbeddedDocuments = int64(in.Int64())
 		case "numberOfEmbeddings":
@@ -1631,6 +1635,16 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(out *jwriter.Writ
 			out.RawByte('}')
 		}
 	}
+	{
+		const prefix string = ",\"rawDocumentDbSize\":"
+		out.RawString(prefix)
+		out.Int64(int64(in.RawDocumentDbSize))
+	}
+	{
+		const prefix string = ",\"avgDocumentSize\":"
+		out.RawString(prefix)
+		out.Int64(int64(in.AvgDocumentSize))
+	}
 	{
 		const prefix string = ",\"numberOfEmbeddedDocuments\":"
 		out.RawString(prefix)



Test patch:
diff --git a/index_test.go b/index_test.go
index a6c9e71..8d96cae 100644
--- a/index_test.go
+++ b/index_test.go
@@ -122,6 +122,8 @@ func TestIndex_GetStats(t *testing.T) {
 				NumberOfDocuments: 6,
 				IsIndexing:        false,
 				FieldDistribution: map[string]int64{"book_id": 6, "title": 6},
+				RawDocumentDbSize: 4096,
+				AvgDocumentSize:   674,
 			},
 		},
 		{
@@ -134,6 +136,8 @@ func TestIndex_GetStats(t *testing.T) {
 				NumberOfDocuments: 6,
 				IsIndexing:        false,
 				FieldDistribution: map[string]int64{"book_id": 6, "title": 6},
+				RawDocumentDbSize: 4096,
+				AvgDocumentSize:   674,
 			},
 		},
 	}