Skip to content

Commit

Permalink
- corrected source formatter
Browse files Browse the repository at this point in the history
- add option to show/hide analyzed warning of a field
  • Loading branch information
scampi committed Dec 5, 2016
1 parent cfed72e commit 3090182
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/ui/public/agg_types/__tests__/metrics/top_hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ describe('Top hit metric', function () {
expect(topHitMetric.makeLabel(aggConfig)).to.eql('First bytes');
});

it('should request the _source field', function () {
init({ field: '_source' });
expect(aggDsl.top_hits._source).to.be(true);
expect(aggDsl.top_hits.docvalue_fields).to.be(undefined);
});

it('should request both for the source and doc_values fields', function () {
init({ field: 'bytes' });
expect(aggDsl.top_hits._source).to.be('bytes');
Expand Down Expand Up @@ -194,7 +200,7 @@ describe('Top hit metric', function () {
expect(topHitMetric.getValue(aggConfig, bucket)).to.be('linux');
});

it('should return null if the field is not in the source nor in the doc_values field', function () {
it('should return undefined if the field is not in the source nor in the doc_values field', function () {
const bucket = {
'1': {
hits: {
Expand All @@ -213,7 +219,7 @@ describe('Top hit metric', function () {
};

init({ field: 'machine.os.raw' });
expect(topHitMetric.getValue(aggConfig, bucket)).to.be(null);
expect(topHitMetric.getValue(aggConfig, bucket)).to.be(undefined);
});
});
});
14 changes: 2 additions & 12 deletions src/ui/public/agg_types/metrics/top_hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function AggTypeMetricTopProvider(Private) {
if (field.type !== 'ip' && field.doc_values) {
output.params.docvalue_fields = [ field.name ];
}
output.params._source = field.name;
output.params._source = field.name === '_source' ? true : field.name;
}
}
},
Expand Down Expand Up @@ -102,17 +102,7 @@ export default function AggTypeMetricTopProvider(Private) {
return null;
}
const path = agg.params.field.name;
let values = agg.vis.indexPattern.flattenHit(hits[0])[path];

if ((values === '' || values === null || values === undefined) && hits[0].fields) {
// no values found in the source, check the doc_values fields
values = hits[0].fields[path] || [];
if (!values.length) {
return null;
}
}

return values;
return path === '_source' ? hits[0]._source : agg.vis.indexPattern.flattenHit(hits[0])[path];
}
});
};
1 change: 1 addition & 0 deletions src/ui/public/agg_types/param_types/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function FieldAggParamFactory(Private, $filter) {
FieldAggParam.prototype.editor = editorHtml;
FieldAggParam.prototype.scriptable = true;
FieldAggParam.prototype.filterFieldTypes = '*';
// retain only the fields with the aggregatable property if the onlyAggregatable option is true
FieldAggParam.prototype.onlyAggregatable = true;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/ui/public/stringify/__tests__/_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ describe('_source formatting', function () {
convertHtml = format.getConverterFor('html');
}));

it('should use the text content type if a field is not passed', function () {
const hit = _.first(hits);
expect(convertHtml(hit._source)).to.be(JSON.stringify(hit._source));
});

it('uses the _source, field, and hit to create a <dl>', function () {
let hit = _.first(hits);
let $dl = $(convertHtml(hit._source, indexPattern.fields.byName._source, hit));
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/stringify/types/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function _SourceFormatProvider(Private, shortDotsFilter) {
Source.prototype._convert = {
text: angular.toJson,
html: function sourceToHtml(source, field, hit) {
if (!field) return this.getConverter('text')(source, field, hit);
if (!field) return this.getConverterFor('text')(source, field, hit);

let highlights = (hit && hit.highlight) || {};
let formatted = field.indexPattern.formatHit(hit);
Expand Down

0 comments on commit 3090182

Please sign in to comment.