From bc0870178c3416068a10387a277c709af3166157 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 30 Oct 2018 00:02:03 -0700 Subject: [PATCH] [Rollups] Fix time field not being recognized due to ordering of aggs (#24783) (#24800) * Fix time field not being recognized due to ordering of aggs * Clean up UI whitespace * Update snapshot --- .../__snapshots__/header.test.js.snap | 6 -- .../components/header/header.js | 1 - .../edit_index_pattern.html | 1 - .../server/routes/api/index_patterns.js | 55 +++++++++++++------ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/__tests__/__snapshots__/header.test.js.snap b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/__tests__/__snapshots__/header.test.js.snap index 71e6009b2c126..8f2ecf83d5890 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/__tests__/__snapshots__/header.test.js.snap +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/__tests__/__snapshots__/header.test.js.snap @@ -2,9 +2,6 @@ exports[`Header should render normally 1`] = `
- @@ -59,9 +56,6 @@ exports[`Header should render normally 1`] = ` exports[`Header should render without including system indices 1`] = `
- diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/header.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/header.js index 5d0490fa05bd5..57407bf7a2233 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/header.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/header/header.js @@ -39,7 +39,6 @@ export const Header = ({ onChangeIncludingSystemIndices, }) => (
-

diff --git a/x-pack/plugins/rollup/server/routes/api/index_patterns.js b/x-pack/plugins/rollup/server/routes/api/index_patterns.js index c453c173b758f..db8b56c788c6f 100644 --- a/x-pack/plugins/rollup/server/routes/api/index_patterns.js +++ b/x-pack/plugins/rollup/server/routes/api/index_patterns.js @@ -69,23 +69,44 @@ export function registerFieldsForWildcardRoute(server) { readFromDocValues: true, }; - rollupFields.push( - ...fields - // For each field of the aggregation, filter out ones that have already been added - // to the field list bcause the same field can be part of multiple aggregations, but - // end consumption doesn't differentiate fields based on their aggregation abilities. - .filter(field => !rollupFieldNames.includes(field)) - // Then expand each field into object format that end consumption expects. - .map(field => { - const fieldCapsKey = `${field}.${agg}.${agg === 'date_histogram' ? 'timestamp' : 'value'}`; - rollupFieldNames.push(field); - return { - ...fieldsFromFieldCapsApi[fieldCapsKey], - ...defaultField, - name: field, - }; - }) - ); + // Date histogram agg only ever has one field defined, let date type overwrite a + // previous type if defined (such as number from max and min aggs). + if(agg === 'date_histogram') { + const timeFieldName = fields[0]; + const fieldCapsKey = `${timeFieldName}.${agg}.timestamp`; + const newField = { + ...fieldsFromFieldCapsApi[fieldCapsKey], + ...defaultField, + name: timeFieldName, + }; + const existingField = rollupFields.find(field => field.name === timeFieldName); + + if(existingField) { + Object.assign(existingField, newField); + } else { + rollupFieldNames.push(timeFieldName); + rollupFields.push(newField); + } + } + // For all other aggs, filter out ones that have already been added to the field list + // because the same field can be part of multiple aggregations, but end consumption + // doesn't differentiate fields based on their aggregation abilities. + else { + rollupFields.push( + ...fields + .filter(field => !rollupFieldNames.includes(field)) + .map(field => { + // Expand each field into object format that end consumption expects. + const fieldCapsKey = `${field}.${agg}.value`; + rollupFieldNames.push(field); + return { + ...fieldsFromFieldCapsApi[fieldCapsKey], + ...defaultField, + name: field, + }; + }) + ); + } }); return reply({ fields: rollupFields