Skip to content

Commit

Permalink
[data.search.aggs] Remove use_field_mapping from top hits agg (#71168)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers authored and APM User committed Jul 14, 2020
1 parent 6a67ed9 commit 0da6bff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/plugins/data/public/search/aggs/metrics/top_hit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ describe('Top hit metric', () => {
it('requests both source and docvalues_fields for non-text aggregatable fields', () => {
init({ fieldName: 'bytes', readFromDocValues: true });
expect(aggDsl.top_hits._source).toBe('bytes');
expect(aggDsl.top_hits.docvalue_fields).toEqual([
{ field: 'bytes', format: 'use_field_mapping' },
]);
expect(aggDsl.top_hits.docvalue_fields).toEqual([{ field: 'bytes' }]);
});

it('requests both source and docvalues_fields for date aggregatable fields', () => {
Expand Down
15 changes: 9 additions & 6 deletions src/plugins/data/public/search/aggs/metrics/top_hit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ export const getTopHitMetricAgg = () => {
};
} else {
if (field.readFromDocValues) {
// always format date fields as date_time to avoid
// displaying unformatted dates like epoch_millis
// or other not-accepted momentjs formats
const format =
field.type === KBN_FIELD_TYPES.DATE ? 'date_time' : 'use_field_mapping';
output.params.docvalue_fields = [{ field: field.name, format }];
output.params.docvalue_fields = [
{
field: field.name,
// always format date fields as date_time to avoid
// displaying unformatted dates like epoch_millis
// or other not-accepted momentjs formats
...(field.type === KBN_FIELD_TYPES.DATE && { format: 'date_time' }),
},
];
}
output.params._source = field.name === '_source' ? true : field.name;
}
Expand Down

0 comments on commit 0da6bff

Please sign in to comment.