Skip to content

Commit

Permalink
[7.17] Don't allow_partial_search_results in readWithPit (#136419) (#…
Browse files Browse the repository at this point in the history
…136509)

* Don't allow_partial_search_results in readWithPit (#136419)

(cherry picked from commit e677179)

* Fix failing backport

Co-authored-by: Gerard Soldevila <[email protected]>
  • Loading branch information
kibanamachine and gsoldevila authored Jul 26, 2022
1 parent af01e8c commit cb8fd9f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,60 @@ describe('readWithPit', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('calls esClient.search with the appropriate params', async () => {
const client = elasticsearchClientMock.createInternalClient(
elasticsearchClientMock.createSuccessTransportRequestPromise({
hits: {
total: 0,
hits: [],
},
})
);

await readWithPit({
client,
pitId: 'pitId',
query: { match_all: {} },
batchSize: 10_000,
})();

expect(client.search).toHaveBeenCalledTimes(1);
expect(client.search).toHaveBeenCalledWith({
allow_partial_search_results: false,
seq_no_primary_term: undefined,
body: {
pit: {
id: 'pitId',
keep_alive: '10m',
},
query: {
match_all: {},
},
search_after: undefined,
size: 10000,
sort: {
_shard_doc: {
order: 'asc',
},
},
track_total_hits: true,
},
});
});

// Create a mock client that rejects all methods with a 503 status code
// response.
const retryableError = new EsErrors.ResponseError(
elasticsearchClientMock.createApiResponse({
statusCode: 503,
body: { error: { type: 'es_type', reason: 'es_reason' } },
})
);
const client = elasticsearchClientMock.createInternalClient(
elasticsearchClientMock.createErrorTransportRequestPromise(retryableError)
);
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
// Create a mock client that rejects all methods with a 503 status code
// response.
const retryableError = new EsErrors.ResponseError(
elasticsearchClientMock.createApiResponse({
statusCode: 503,
body: { error: { type: 'es_type', reason: 'es_reason' } },
})
);
const client = elasticsearchClientMock.createInternalClient(
elasticsearchClientMock.createErrorTransportRequestPromise(retryableError)
);

const task = readWithPit({
client,
pitId: 'pitId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const readWithPit =
() => {
return client
.search<SavedObjectsRawDoc>({
allow_partial_search_results: false,
seq_no_primary_term: seqNoPrimaryTerm,
body: {
// Sort fields are required to use searchAfter
Expand Down

0 comments on commit cb8fd9f

Please sign in to comment.