Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/reference/aggregations/matrix/stats-aggregation.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ the statistics. The above request returns the following response:
...
"aggregations": {
"matrixstats": {
"doc_count": 50,
"fields": [{
"name": "income",
"count": 50,
Expand Down Expand Up @@ -73,6 +74,8 @@ the statistics. The above request returns the following response:
}
--------------------------------------------------

The `doc_count` field indicates the number of documents involved in the computation of the statistics.

==== Multi Value Fields

The `matrix_stats` aggregation treats each document field as an independent sample. The `mode` parameter controls what
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public String getWriteableName() {
/** get the number of documents */
@Override
public long getDocCount() {
if (stats == null) {
return 0;
}
return stats.docCount;
}

Expand Down Expand Up @@ -157,6 +160,7 @@ static class Fields {

@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount());
if (results != null && results.getFieldCounts().keySet().isEmpty() == false) {
builder.startArray(Fields.FIELDS);
for (String fieldName : results.getFieldCounts().keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"]} } } }

- match: {hits.total: 0}
- match: {aggregations.mfs.doc_count: 0}

---
"Single value field":
Expand All @@ -144,6 +145,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val3"]} } } }

- match: {hits.total: 15}
- match: {aggregations.mfs.doc_count: 15}
- match: {aggregations.mfs.fields.0.count: 15}

---
Expand All @@ -156,6 +158,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"]} } } }

- match: {hits.total: 15}
- match: {aggregations.mfs.doc_count: 14}
- match: {aggregations.mfs.fields.0.count: 14}
- match: {aggregations.mfs.fields.2.correlation.val2: 0.9569513137793205}

Expand All @@ -169,6 +172,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "val3"], "missing" : {"val2" : 10} } } } }

- match: {hits.total: 15}
- match: {aggregations.mfs.doc_count: 15}
- match: {aggregations.mfs.fields.0.count: 15}
- match: {aggregations.mfs.fields.2.correlation.val2: 0.9567970467908384}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "vals"]} } } }

- match: {hits.total: 0}
- match: {aggregations.mfs.doc_count: 0}

---
"Multi value field Max":
Expand All @@ -144,6 +145,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "vals"], "mode" : "max"} } } }

- match: {hits.total: 15}
- match: {aggregations.mfs.doc_count: 14}
- match: {aggregations.mfs.fields.0.count: 14}
- match: {aggregations.mfs.fields.0.correlation.val1: 0.06838646533369998}

Expand All @@ -157,6 +159,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "vals"], "mode" : "min"} } } }

- match: {hits.total: 15}
- match: {aggregations.mfs.doc_count: 14}
- match: {aggregations.mfs.fields.0.count: 14}
- match: {aggregations.mfs.fields.0.correlation.val1: -0.09777682707831963}

Expand All @@ -170,6 +173,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "vals"]} } } }

- match: {hits.total: 15}
- match: {aggregations.mfs.doc_count: 13}
- match: {aggregations.mfs.fields.0.count: 13}
- match: {aggregations.mfs.fields.0.correlation.val1: -0.044997535185684244}

Expand All @@ -183,6 +187,7 @@ setup:
body: {"aggs": { "mfs" : { "matrix_stats": {"fields": ["val1", "val2", "vals"], "missing" : {"val2" : 10, "vals" : 5 } } } } }

- match: {hits.total: 15}
- match: {aggregations.mfs.doc_count: 15}
- match: {aggregations.mfs.fields.0.count: 15}
- match: {aggregations.mfs.fields.0.correlation.val2: 0.04028024709708195}

Expand Down