mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Fix sort for rollup data views (#214656)
## Summary Resolves https://github.com/elastic/kibana/issues/213629. Since https://github.com/elastic/kibana/pull/163784 we have included a `format` parameter in the `sort` that we send to Elasticsearch. This worked for everything except rollup data views, which break when the `format` parameter is provided. This restores the behavior prior to that PR (we still send the `sort` but don't include the `format` parameter). Ideally we would probably not send the timestamp field at all for rollup data views since we treat them as if they are non-time-based, but this would require a bit of a refactor, and rollups are deprecated anyway. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed ### Release notes Fixes opening a rollup data view in Discover. Co-authored-by: Matthew Kime <matt@mattki.me>
This commit is contained in:
parent
a7cc00c4fe
commit
2de4b331d3
3 changed files with 38 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { DataViewType } from './types';
|
||||
import { stubFieldSpecMap, stubLogstashFieldSpecMap } from './field.stub';
|
||||
import { createStubDataView } from './data_views/data_view.stub';
|
||||
export {
|
||||
|
@ -23,6 +24,16 @@ export const stubDataView = createStubDataView({
|
|||
},
|
||||
});
|
||||
|
||||
export const stubRollupDataView = createStubDataView({
|
||||
spec: {
|
||||
id: 'logstash-*',
|
||||
fields: stubFieldSpecMap,
|
||||
title: 'logstash-*',
|
||||
timeFieldName: '@timestamp',
|
||||
type: DataViewType.ROLLUP,
|
||||
},
|
||||
});
|
||||
|
||||
export const stubIndexPattern = stubDataView;
|
||||
|
||||
export const stubDataViewWithoutTimeField = createStubDataView({
|
||||
|
|
|
@ -9,7 +9,11 @@
|
|||
|
||||
import type { SortOrder } from '@kbn/saved-search-plugin/public';
|
||||
import { getSortForSearchSource } from './get_sort_for_search_source';
|
||||
import { stubDataView, stubDataViewWithoutTimeField } from '@kbn/data-plugin/common/stubs';
|
||||
import {
|
||||
stubDataView,
|
||||
stubDataViewWithoutTimeField,
|
||||
stubRollupDataView,
|
||||
} from '@kbn/data-plugin/common/stubs';
|
||||
|
||||
describe('getSortForSearchSource function', function () {
|
||||
test('should be a function', function () {
|
||||
|
@ -94,4 +98,24 @@ describe('getSortForSearchSource function', function () {
|
|||
})
|
||||
).toEqual([{ _score: 'asc' }]);
|
||||
});
|
||||
|
||||
test('should return an object including format when data view is not a rollup', function () {
|
||||
expect(
|
||||
getSortForSearchSource({
|
||||
sort: [['@timestamp', 'desc']],
|
||||
dataView: stubDataView,
|
||||
defaultSortDir: 'desc',
|
||||
})
|
||||
).toEqual([{ '@timestamp': { format: 'strict_date_optional_time', order: 'desc' } }]);
|
||||
});
|
||||
|
||||
test('should not return an object excluding format when data view is a rollup', function () {
|
||||
expect(
|
||||
getSortForSearchSource({
|
||||
sort: [['@timestamp', 'desc']],
|
||||
dataView: stubRollupDataView,
|
||||
defaultSortDir: 'desc',
|
||||
})
|
||||
).toEqual([{ '@timestamp': 'desc' }]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type { DataView } from '@kbn/data-views-plugin/common';
|
||||
import { type DataView, DataViewType } from '@kbn/data-views-plugin/common';
|
||||
import type { EsQuerySortValue, SortDirection } from '@kbn/data-plugin/common';
|
||||
import type { SortOrder } from '@kbn/saved-search-plugin/public';
|
||||
import { getSort } from './get_sort';
|
||||
|
@ -50,7 +50,7 @@ export function getSortForSearchSource({
|
|||
const sortPairs = getSort(sort, dataView, false); // ES|QL request is not using search source
|
||||
|
||||
const sortForSearchSource = sortPairs.map((sortPair: Record<string, string>) => {
|
||||
if (timeFieldName && sortPair[timeFieldName]) {
|
||||
if (dataView.type !== DataViewType.ROLLUP && timeFieldName && sortPair[timeFieldName]) {
|
||||
return getESQuerySortForTimeField({
|
||||
sortDir: sortPair[timeFieldName] as SortDirection,
|
||||
timeFieldName,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue