From 8e9911e4692fd2b4487368306786731f943d9440 Mon Sep 17 00:00:00 2001 From: Maja Grubic Date: Fri, 5 Feb 2021 10:39:10 +0000 Subject: [PATCH] [Search Source] Specify strict_date_optional_time_nanos as a formatter for date_nanos field --- .../common/index_patterns/index_patterns/index_pattern.ts | 2 +- .../data/common/search/search_source/search_source.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index ca4fee0416ac4..7223865198b66 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -179,7 +179,7 @@ export class IndexPattern implements IIndexPattern { field: dateField.name, format: dateField.esTypes && dateField.esTypes.indexOf('date_nanos') !== -1 - ? 'strict_date_time' + ? 'strict_date_optional_time_nanos' : 'date_time', }; } diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index 1c1360414cb2e..6e7fb617a9429 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -614,6 +614,7 @@ export class SearchSource { // if items that are in the docvalueFields are provided, we should // inject the format from the computed fields if one isn't given const docvaluesIndex = keyBy(filteredDocvalueFields, 'field'); + const formatterIndex = keyBy(filteredDocvalueFields, 'format'); body.fields = body.fields.map((fld: SearchFieldValue) => { const fieldName = getFieldName(fld); if (Object.keys(docvaluesIndex).includes(fieldName)) { @@ -626,6 +627,10 @@ export class SearchSource { ...fld, }; } + if (Object.keys(formatterIndex).includes('strict_date_optional_time_nanos')) { + // @ts-ignore + fld.format = 'strict_date_optional_time_nanos'; + } return fld; }); }