Skip to content

Commit

Permalink
[APM] Add rest_total_hits_as_int to all ES requests (elastic#26462) (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Dec 6, 2018
1 parent 0cab638 commit bb79d69
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
47 changes: 47 additions & 0 deletions x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { setupRequest } from './setup_request';

describe('setupRequest', () => {
let callWithRequestSpy: jest.Mock;
let mockReq: any;

beforeEach(() => {
callWithRequestSpy = jest.fn();
mockReq = {
params: {},
query: {},
server: {
config: () => 'myConfig',
plugins: {
elasticsearch: {
getCluster: () => ({
callWithRequest: callWithRequestSpy
})
}
}
}
};

const setup = setupRequest(mockReq);
setup.client('myType', { body: 'foo' });
});

it('should call callWithRequest with correct args', () => {
expect(callWithRequestSpy).toHaveBeenCalledWith(mockReq, 'myType', {
body: 'foo',
rest_total_hits_as_int: true
});
});

it('should update params with rest_total_hits_as_int', () => {
expect(callWithRequestSpy.mock.calls[0][2]).toEqual({
body: 'foo',
rest_total_hits_as_int: true
});
});
});
7 changes: 6 additions & 1 deletion x-pack/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ export function setupRequest(req: Request): Setup {
console.log(`GET ${params.index}/_search`);
console.log(JSON.stringify(params.body, null, 4));
}
return cluster.callWithRequest(req, type, params);

const nextParams = {
...params,
rest_total_hits_as_int: true // ensure that ES returns accurate hits.total with pre-6.6 format
};
return cluster.callWithRequest(req, type, nextParams);
};

return {
Expand Down

0 comments on commit bb79d69

Please sign in to comment.