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

[Discover] Fix tiebreaker sort order in context view #32225

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('context app', function () {
it('should use the `fetch` method of the SearchSource', function () {
const searchSourceStub = new SearchSourceStub();

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(() => {
expect(searchSourceStub.fetch.calledOnce).to.be(true);
});
Expand All @@ -77,7 +77,7 @@ describe('context app', function () {
it('should configure the SearchSource to not inherit from the implicit root', function () {
const searchSourceStub = new SearchSourceStub();

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(() => {
const setParentSpy = searchSourceStub.setParent;
expect(setParentSpy.calledOnce).to.be(true);
Expand All @@ -88,7 +88,7 @@ describe('context app', function () {
it('should set the SearchSource index pattern', function () {
const searchSourceStub = new SearchSourceStub();

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(() => {
const setFieldSpy = searchSourceStub.setField;
expect(setFieldSpy.firstCall.args[1]).to.eql({ id: 'INDEX_PATTERN_ID' });
Expand All @@ -98,7 +98,7 @@ describe('context app', function () {
it('should set the SearchSource version flag to true', function () {
const searchSourceStub = new SearchSourceStub();

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(() => {
const setVersionSpy = searchSourceStub.setField.withArgs('version');
expect(setVersionSpy.calledOnce).to.be(true);
Expand All @@ -109,7 +109,7 @@ describe('context app', function () {
it('should set the SearchSource size to 1', function () {
const searchSourceStub = new SearchSourceStub();

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(() => {
const setSizeSpy = searchSourceStub.setField.withArgs('size');
expect(setSizeSpy.calledOnce).to.be(true);
Expand All @@ -120,7 +120,7 @@ describe('context app', function () {
it('should set the SearchSource query to an ids query', function () {
const searchSourceStub = new SearchSourceStub();

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(() => {
const setQuerySpy = searchSourceStub.setField.withArgs('query');
expect(setQuerySpy.calledOnce).to.be(true);
Expand All @@ -143,13 +143,13 @@ describe('context app', function () {
it('should set the SearchSource sort order', function () {
const searchSourceStub = new SearchSourceStub();

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(() => {
const setSortSpy = searchSourceStub.setField.withArgs('sort');
expect(setSortSpy.calledOnce).to.be(true);
expect(setSortSpy.firstCall.args[1]).to.eql([
{ '@timestamp': 'desc' },
{ '_doc': 'asc' },
{ '_doc': 'desc' },
]);
});
});
Expand All @@ -158,7 +158,7 @@ describe('context app', function () {
const searchSourceStub = new SearchSourceStub();
searchSourceStub._stubHits = [];

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then(
() => {
expect().fail('expected the promise to be rejected');
Expand All @@ -176,7 +176,7 @@ describe('context app', function () {
{ property2: 'value2' },
];

return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
.then((anchorDocument) => {
expect(anchorDocument).to.have.property('property1', 'value1');
expect(anchorDocument).to.have.property('$$_isAnchor', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3000,
'_doc',
'asc',
0,
3,
[]
Expand All @@ -89,7 +88,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3000,
'_doc',
'asc',
0,
6,
[]
Expand Down Expand Up @@ -125,7 +123,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 1000,
'_doc',
'asc',
0,
3,
[]
Expand All @@ -152,7 +149,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3,
'_doc',
'asc',
0,
3,
[]
Expand All @@ -171,7 +167,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3,
'_doc',
'asc',
0,
3,
[]
Expand All @@ -182,5 +177,26 @@ describe('context app', function () {
expect(setParentSpy.called).to.be(true);
});
});

it('should set the tiebreaker sort order to the opposite as the time field', function () {
const searchSourceStub = getSearchSourceStub();

return fetchPredecessors(
'INDEX_PATTERN_ID',
'@timestamp',
'desc',
MS_PER_DAY,
'_doc',
0,
3,
[]
)
.then(() => {
expect(searchSourceStub.setField.calledWith('sort', [
{ '@timestamp': 'asc' },
{ '_doc': 'asc' },
])).to.be(true);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3000,
'_doc',
'asc',
0,
3,
[]
Expand All @@ -89,7 +88,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3000,
'_doc',
'asc',
0,
6,
[]
Expand Down Expand Up @@ -127,7 +125,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3000,
'_doc',
'asc',
0,
4,
[]
Expand All @@ -154,7 +151,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3,
'_doc',
'asc',
0,
3,
[]
Expand All @@ -173,7 +169,6 @@ describe('context app', function () {
'desc',
MS_PER_DAY * 3,
'_doc',
'asc',
0,
3,
[]
Expand All @@ -184,5 +179,26 @@ describe('context app', function () {
expect(setParentSpy.called).to.be(true);
});
});

it('should set the tiebreaker sort order to the same as the time field', function () {
const searchSourceStub = getSearchSourceStub();

return fetchSuccessors(
'INDEX_PATTERN_ID',
'@timestamp',
'desc',
MS_PER_DAY,
'_doc',
0,
3,
[]
)
.then(() => {
expect(searchSourceStub.setField.calledWith('sort', [
{ '@timestamp': 'desc' },
{ '_doc': 'desc' },
])).to.be(true);
});
});
});
});
10 changes: 2 additions & 8 deletions src/legacy/core_plugins/kibana/public/context/api/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function fetchContextProvider(indexPatterns, Private) {
timeSortDirection,
timeValue,
tieBreakerField,
tieBreakerSortDirection,
tieBreakerValue,
size,
filters
Expand Down Expand Up @@ -94,7 +93,6 @@ function fetchContextProvider(indexPatterns, Private) {
endTimeValue,
afterTimeValue,
tieBreakerField,
tieBreakerSortDirection,
afterTieBreakerValue,
remainingSize
);
Expand All @@ -111,7 +109,6 @@ function fetchContextProvider(indexPatterns, Private) {
timeSortDirection,
timeValue,
tieBreakerField,
tieBreakerSortDirection,
tieBreakerValue,
size,
filters
Expand Down Expand Up @@ -142,7 +139,6 @@ function fetchContextProvider(indexPatterns, Private) {
endTimeValue,
afterTimeValue,
tieBreakerField,
reverseSortDirection(tieBreakerSortDirection),
afterTieBreakerValue,
remainingSize
);
Expand Down Expand Up @@ -172,7 +168,7 @@ function fetchContextProvider(indexPatterns, Private) {
* `endTimeValue` from the `searchSource` using the given `timeField` and
* `tieBreakerField` fields up to a maximum of `maxCount` documents. The
* documents are sorted by `(timeField, tieBreakerField)` using the
* respective `timeSortDirection` and `tieBreakerSortDirection`.
* `timeSortDirection` for both fields
*
* The `searchSource` is assumed to have the appropriate index pattern
* and filters set.
Expand All @@ -184,7 +180,6 @@ function fetchContextProvider(indexPatterns, Private) {
* @param {number | null} endTimeValue
* @param {number} [afterTimeValue=startTimeValue]
* @param {string} tieBreakerField
* @param {SortDirection} tieBreakerSortDirection
* @param {number} tieBreakerValue
* @param {number} maxCount
* @returns {Promise<object[]>}
Expand All @@ -197,7 +192,6 @@ function fetchContextProvider(indexPatterns, Private) {
endTimeValue,
afterTimeValue,
tieBreakerField,
tieBreakerSortDirection,
tieBreakerValue,
maxCount
) {
Expand Down Expand Up @@ -232,7 +226,7 @@ function fetchContextProvider(indexPatterns, Private) {
])
.setField('sort', [
{ [timeField]: timeSortDirection },
{ [tieBreakerField]: tieBreakerSortDirection },
{ [tieBreakerField]: timeSortDirection },
])
.setField('version', true)
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function QueryActionsProvider(courier, Private, Promise, i18n) {
setLoadingStatus(state)('anchor');

return Promise.try(() => (
fetchAnchor(indexPatternId, anchorType, anchorId, [_.zipObject([sort]), { [tieBreakerField]: 'asc' }])
fetchAnchor(indexPatternId, anchorType, anchorId, [_.zipObject([sort]), { [tieBreakerField]: sort[1] }])
))
.then(
(anchorDocument) => {
Expand Down Expand Up @@ -112,7 +112,6 @@ export function QueryActionsProvider(courier, Private, Promise, i18n) {
sort[1],
anchor.sort[0],
tieBreakerField,
'asc',
anchor.sort[1],
predecessorCount,
filters
Expand Down Expand Up @@ -158,7 +157,6 @@ export function QueryActionsProvider(courier, Private, Promise, i18n) {
sort[1],
anchor.sort[0],
tieBreakerField,
'asc',
anchor.sort[1],
successorCount,
filters
Expand Down