Skip to content

Commit eea010b

Browse files
authored
Add doc_count to ParsedMatrixStats (#24952)
This commit adds support in ParsedMatrixStats for parsing the doc_count field. Related to #24776
1 parent 28d97df commit eea010b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/ParsedMatrixStats.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ public class ParsedMatrixStats extends ParsedAggregation implements MatrixStats
4141
private final Map<String, Map<String, Double>> covariances = new HashMap<>();
4242
private final Map<String, Map<String, Double>> correlations = new HashMap<>();
4343

44+
private long docCount;
45+
4446
@Override
4547
public String getType() {
4648
return MatrixStatsAggregationBuilder.NAME;
4749
}
4850

51+
private void setDocCount(long docCount) {
52+
this.docCount = docCount;
53+
}
54+
4955
@Override
5056
public long getDocCount() {
51-
throw new UnsupportedOperationException();
57+
return docCount;
5258
}
5359

5460
@Override
@@ -97,6 +103,7 @@ public double getCorrelation(String fieldX, String fieldY) {
97103

98104
@Override
99105
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
106+
builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount());
100107
if (counts != null && counts.isEmpty() == false) {
101108
builder.startArray(InternalMatrixStats.Fields.FIELDS);
102109
for (String fieldName : counts.keySet()) {
@@ -148,6 +155,7 @@ private static <T> T checkedGet(final Map<String, T> values, final String fieldN
148155
new ObjectParser<>(ParsedMatrixStats.class.getSimpleName(), true, ParsedMatrixStats::new);
149156
static {
150157
declareAggregationFields(PARSER);
158+
PARSER.declareLong(ParsedMatrixStats::setDocCount, CommonFields.DOC_COUNT);
151159
PARSER.declareObjectArray((matrixStats, results) -> {
152160
for (ParsedMatrixStatsResult result : results) {
153161
final String fieldName = result.name;

modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/stats/InternalMatrixStatsTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ protected void assertFromXContent(InternalMatrixStats expected, ParsedAggregatio
133133
assertTrue(parsedAggregation instanceof ParsedMatrixStats);
134134
ParsedMatrixStats actual = (ParsedMatrixStats) parsedAggregation;
135135

136-
//norelease add parsing logic for doc count and enable this test once elastic/elasticsearch#24776 is merged
137-
//assertEquals(expected.getDocCount(), actual.getDocCount());
136+
assertEquals(expected.getDocCount(), actual.getDocCount());
138137

139138
for (String field : fields) {
140139
assertEquals(expected.getFieldCount(field), actual.getFieldCount(field));

0 commit comments

Comments
 (0)