diff --git a/x-pack/plugins/maps/common/mvt_request_body.test.ts b/x-pack/plugins/maps/common/mvt_request_body.test.ts index bb8945231b701..3a8c654b2979d 100644 --- a/x-pack/plugins/maps/common/mvt_request_body.test.ts +++ b/x-pack/plugins/maps/common/mvt_request_body.test.ts @@ -52,6 +52,26 @@ describe('getHitsTileRequest', () => { expect(path).toEqual('/my%20index/_mvt/my%20location/0/0/0'); }); + test(`Should use requestBody.size to set both track_total_hits and size parameters`, () => { + const searchRequest = { + size: 20000, + runtime_mappings: {}, + query: {}, + }; + const { body } = getHitsTileRequest({ + buffer: 5, + risonRequestBody: rison.encode(searchRequest), + geometryFieldName: 'my location', + hasLabels: true, + index: 'my index', + x: 0, + y: 0, + z: 0, + }); + expect(body?.track_total_hits).toEqual(20001); + expect(body?.size).toEqual(20000); + }); + describe('sort', () => { test(`Should include sort`, () => { const searchRequest = { diff --git a/x-pack/plugins/maps/common/mvt_request_body.ts b/x-pack/plugins/maps/common/mvt_request_body.ts index 9a765505960ef..d87707ad6b908 100644 --- a/x-pack/plugins/maps/common/mvt_request_body.ts +++ b/x-pack/plugins/maps/common/mvt_request_body.ts @@ -83,6 +83,7 @@ export function getHitsTileRequest({ if (!requestBody) { throw new Error('Required requestBody parameter not provided'); } + const size = typeof requestBody.size === 'number' ? requestBody.size : 10000; const tileRequestBody = { buffer, grid_precision: 0, // no aggs @@ -90,7 +91,12 @@ export function getHitsTileRequest({ extent: 4096, // full resolution, query: requestBody.query, runtime_mappings: requestBody.runtime_mappings, - track_total_hits: typeof requestBody.size === 'number' ? requestBody.size + 1 : false, + // Number of hits matching the query to count accurately + // Used to notify users of truncated results + track_total_hits: size + 1, + // Maximum number of features to return in the hits layer + // Used to fetch number of hits that correspondes with track_total_hits + size, with_labels: hasLabels, } as SearchMvtRequest['body']; if (requestBody.fields) { diff --git a/x-pack/plugins/maps/public/inspector/vector_tile_adapter/components/get_tile_request.test.ts b/x-pack/plugins/maps/public/inspector/vector_tile_adapter/components/get_tile_request.test.ts index 922d45b2effc7..c8bb1a8fb81bc 100644 --- a/x-pack/plugins/maps/public/inspector/vector_tile_adapter/components/get_tile_request.test.ts +++ b/x-pack/plugins/maps/public/inspector/vector_tile_adapter/components/get_tile_request.test.ts @@ -126,6 +126,7 @@ test('Should return elasticsearch vector tile request for hits tiles', () => { type: 'long', }, }, + size: 10000, sort: [ { '@timestamp': {