Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [data.search.aggs] Remove use_field_mapping from top hits agg (#71168) #71649

Merged
merged 1 commit into from
Jul 14, 2020
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
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