Skip to content

Commit

Permalink
[ML] Fix counters and percentages for array fields on the Data visual…
Browse files Browse the repository at this point in the history
…izer page (#55209) (#55519)

* [ML] update data visualizer endpoint to check doc counts

* [ML] fix mock for cardinality tests

* [ML] use actual field name for agg filtering instead of safeFieldName

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
darnautov and elasticmachine authored Jan 22, 2020
1 parent c942e7a commit e7672a8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class DataVisualizer {
aggregatableFields.forEach((field, i) => {
const safeFieldName = getSafeAggregationName(field, i);
aggs[`${safeFieldName}_count`] = {
value_count: { field },
filter: { exists: { field } },
};
aggs[`${safeFieldName}_cardinality`] = {
cardinality: { field },
Expand Down Expand Up @@ -296,7 +296,7 @@ export class DataVisualizer {
samplerShardSize > 0 ? _.get(aggregations, ['sample', 'doc_count'], 0) : totalCount;
aggregatableFields.forEach((field, i) => {
const safeFieldName = getSafeAggregationName(field, i);
const count = _.get(aggregations, [...aggsPath, `${safeFieldName}_count`, 'value'], 0);
const count = _.get(aggregations, [...aggsPath, `${safeFieldName}_count`, 'doc_count'], 0);
if (count > 0) {
const cardinality = _.get(
aggregations,
Expand Down Expand Up @@ -433,7 +433,12 @@ export class DataVisualizer {
fields.forEach((field, i) => {
const safeFieldName = getSafeAggregationName(field.fieldName, i);
aggs[`${safeFieldName}_field_stats`] = {
stats: { field: field.fieldName },
filter: { exists: { field: field.fieldName } },
aggs: {
actual_stats: {
stats: { field: field.fieldName },
},
},
};
aggs[`${safeFieldName}_percentiles`] = {
percentiles: {
Expand Down Expand Up @@ -484,10 +489,19 @@ export class DataVisualizer {
const batchStats = [];
fields.forEach((field, i) => {
const safeFieldName = getSafeAggregationName(field.fieldName, i);
const fieldStatsResp = _.get(aggregations, [...aggsPath, `${safeFieldName}_field_stats`], {});
const docCount = _.get(
aggregations,
[...aggsPath, `${safeFieldName}_field_stats`, 'doc_count'],
0
);
const fieldStatsResp = _.get(
aggregations,
[...aggsPath, `${safeFieldName}_field_stats`, 'actual_stats'],
{}
);
const stats = {
fieldName: field.fieldName,
count: _.get(fieldStatsResp, 'count', 0),
count: docCount,
min: _.get(fieldStatsResp, 'min', 0),
max: _.get(fieldStatsResp, 'max', 0),
avg: _.get(fieldStatsResp, 'avg', 0),
Expand Down Expand Up @@ -632,7 +646,12 @@ export class DataVisualizer {
fields.forEach((field, i) => {
const safeFieldName = getSafeAggregationName(field.fieldName, i);
aggs[`${safeFieldName}_field_stats`] = {
stats: { field: field.fieldName },
filter: { exists: { field: field.fieldName } },
aggs: {
actual_stats: {
stats: { field: field.fieldName },
},
},
};
});

Expand All @@ -651,10 +670,19 @@ export class DataVisualizer {
const batchStats = [];
fields.forEach((field, i) => {
const safeFieldName = getSafeAggregationName(field.fieldName, i);
const fieldStatsResp = _.get(aggregations, [...aggsPath, `${safeFieldName}_field_stats`], {});
const docCount = _.get(
aggregations,
[...aggsPath, `${safeFieldName}_field_stats`, 'doc_count'],
0
);
const fieldStatsResp = _.get(
aggregations,
[...aggsPath, `${safeFieldName}_field_stats`, 'actual_stats'],
{}
);
batchStats.push({
fieldName: field.fieldName,
count: _.get(fieldStatsResp, 'count', 0),
count: docCount,
earliest: _.get(fieldStatsResp, 'min', 0),
latest: _.get(fieldStatsResp, 'max', 0),
});
Expand All @@ -680,7 +708,7 @@ export class DataVisualizer {
fields.forEach((field, i) => {
const safeFieldName = getSafeAggregationName(field.fieldName, i);
aggs[`${safeFieldName}_value_count`] = {
value_count: { field: field.fieldName },
filter: { exists: { field: field.fieldName } },
};
aggs[`${safeFieldName}_values`] = {
terms: {
Expand All @@ -707,7 +735,7 @@ export class DataVisualizer {
const safeFieldName = getSafeAggregationName(field.fieldName, i);
const stats = {
fieldName: field.fieldName,
count: _.get(aggregations, [...aggsPath, `${safeFieldName}_value_count`, 'value'], 0),
count: _.get(aggregations, [...aggsPath, `${safeFieldName}_value_count`, 'doc_count'], 0),
trueCount: 0,
falseCount: 0,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{"took":0,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":86274,"max_score":0,"hits":[]},"aggregations":{"airline_cardinality":{"value":19},"airline_count":{"value":86274}}}
{
"took": 0,
"timed_out": false,
"_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 },
"hits": { "total": 86274, "max_score": 0, "hits": [] },
"aggregations": { "airline_cardinality": { "value": 19 }, "airline_count": { "doc_count": 86274 } }
}

0 comments on commit e7672a8

Please sign in to comment.