Skip to content

Commit

Permalink
[core.savedObjects] Remove _shard_doc tiebreaker since ES now adds it…
Browse files Browse the repository at this point in the history
… automatically. (#92295) (#92818)

Co-authored-by: Luke Elmers <[email protected]>
  • Loading branch information
kibanamachine and lukeelmers authored Feb 25, 2021
1 parent 527f026 commit f22db71
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ describe('getSearchDsl', () => {
mappings,
opts.type,
opts.sortField,
opts.sortOrder,
opts.pit
opts.sortOrder
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function getSearchDsl(
hasReferenceOperator,
kueryNode,
}),
...getSortingParams(mappings, type, sortField, sortOrder, pit),
...getSortingParams(mappings, type, sortField, sortOrder),
...(pit ? getPitParams(pit) : {}),
...(searchAfter ? { search_after: searchAfter } : {}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ describe('searchDsl/getSortParams', () => {
],
});
});
it('appends tiebreaker when PIT is provided', () => {
expect(getSortingParams(MAPPINGS, 'saved', 'title', undefined, { id: 'abc' }).sort).toEqual(
expect.arrayContaining([{ _shard_doc: 'asc' }])
);
});
});
describe('sortField is simple root property with multiple types', () => {
it('returns correct params', () => {
Expand All @@ -98,11 +93,6 @@ describe('searchDsl/getSortParams', () => {
],
});
});
it('appends tiebreaker when PIT is provided', () => {
expect(
getSortingParams(MAPPINGS, ['saved', 'pending'], 'type', undefined, { id: 'abc' }).sort
).toEqual(expect.arrayContaining([{ _shard_doc: 'asc' }]));
});
});
describe('sortField is simple non-root property with multiple types', () => {
it('returns correct params', () => {
Expand All @@ -124,11 +114,6 @@ describe('searchDsl/getSortParams', () => {
],
});
});
it('appends tiebreaker when PIT is provided', () => {
expect(
getSortingParams(MAPPINGS, 'saved', 'title.raw', undefined, { id: 'abc' }).sort
).toEqual(expect.arrayContaining([{ _shard_doc: 'asc' }]));
});
});
describe('sortField is multi-field with single type as array', () => {
it('returns correct params', () => {
Expand All @@ -143,11 +128,6 @@ describe('searchDsl/getSortParams', () => {
],
});
});
it('appends tiebreaker when PIT is provided', () => {
expect(
getSortingParams(MAPPINGS, ['saved'], 'title.raw', undefined, { id: 'abc' }).sort
).toEqual(expect.arrayContaining([{ _shard_doc: 'asc' }]));
});
});
describe('sortField is root multi-field with multiple types', () => {
it('returns correct params', () => {
Expand All @@ -162,12 +142,6 @@ describe('searchDsl/getSortParams', () => {
],
});
});
it('appends tiebreaker when PIT is provided', () => {
expect(
getSortingParams(MAPPINGS, ['saved', 'pending'], 'type.raw', undefined, { id: 'abc' })
.sort
).toEqual(expect.arrayContaining([{ _shard_doc: 'asc' }]));
});
});
describe('sortField is not-root multi-field with multiple types', () => {
it('returns correct params', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@

import Boom from '@hapi/boom';
import { getProperty, IndexMapping } from '../../../mappings';
import { SavedObjectsPitParams } from '../../../types';

// TODO: The plan is for ES to automatically add this tiebreaker when
// using PIT. We should remove this logic once that is resolved.
// https://github.com/elastic/elasticsearch/issues/56828
const ES_PROVIDED_TIEBREAKER = { _shard_doc: 'asc' };

const TOP_LEVEL_FIELDS = ['_id', '_score'];

export function getSortingParams(
mappings: IndexMapping,
type: string | string[],
sortField?: string,
sortOrder?: string,
pit?: SavedObjectsPitParams
sortOrder?: string
) {
if (!sortField) {
return {};
Expand All @@ -38,7 +31,6 @@ export function getSortingParams(
order: sortOrder,
},
},
...(pit ? [ES_PROVIDED_TIEBREAKER] : []),
],
};
}
Expand All @@ -59,7 +51,6 @@ export function getSortingParams(
unmapped_type: rootField.type,
},
},
...(pit ? [ES_PROVIDED_TIEBREAKER] : []),
],
};
}
Expand All @@ -84,7 +75,6 @@ export function getSortingParams(
unmapped_type: field.type,
},
},
...(pit ? [ES_PROVIDED_TIEBREAKER] : []),
],
};
}

0 comments on commit f22db71

Please sign in to comment.