Skip to content

Commit

Permalink
[Rollups] Fix time field not being recognized due to ordering of aggs (
Browse files Browse the repository at this point in the history
…elastic#24783) (elastic#24800)

* Fix time field not being recognized due to ordering of aggs

* Clean up UI whitespace

* Update snapshot
  • Loading branch information
jen-huang authored Oct 30, 2018
1 parent 1c7ec69 commit bc08701
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

exports[`Header should render normally 1`] = `
<div>
<EuiSpacer
size="m"
/>
<EuiTitle
size="m"
>
Expand Down Expand Up @@ -59,9 +56,6 @@ exports[`Header should render normally 1`] = `

exports[`Header should render without including system indices 1`] = `
<div>
<EuiSpacer
size="m"
/>
<EuiTitle
size="m"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const Header = ({
onChangeIncludingSystemIndices,
}) => (
<div>
<EuiSpacer size="m"/>
<EuiTitle>
<h1>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<div
ng-controller="managementIndicesEdit"
data-test-subj="editIndexPattern"
class="kuiViewContent"
role="region"
aria-label="{{::'kbn.management.editIndexPattern.detailsAria' | i18n: { defaultMessage: 'Index pattern details' } }}"
>
Expand Down
55 changes: 38 additions & 17 deletions x-pack/plugins/rollup/server/routes/api/index_patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc08701

Please sign in to comment.