[APM] Add rest_total_hits_as_int to all ES requests (#26462)

This commit is contained in:
Søren Louv-Jansen 2018-12-06 12:49:09 +01:00 committed by GitHub
parent 15636c4f6b
commit d3330a6ea9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 1 deletions

View file

@ -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
});
});
});

View file

@ -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 {