Skip to content

Commit

Permalink
only send metric aggregations to mvt/getGridTile endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Oct 22, 2021
1 parent e003e97 commit 0e4e68a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ describe('ESGeoGridSource', () => {
expect(urlTemplateWithMeta.minSourceZoom).toBe(0);
expect(urlTemplateWithMeta.maxSourceZoom).toBe(24);
expect(urlTemplateWithMeta.urlTemplate).toEqual(
"rootdir/api/maps/mvt/getGridTile/{z}/{x}/{y}.pbf?geometryFieldName=bar&index=undefined&requestBody=(foobar:ES_DSL_PLACEHOLDER,params:('0':('0':index,'1':(fields:())),'1':('0':size,'1':0),'2':('0':filter,'1':!()),'3':('0':query),'4':('0':index,'1':(fields:())),'5':('0':query,'1':(language:KQL,query:'')),'6':('0':aggs,'1':(gridSplit:(aggs:(gridCentroid:(geo_centroid:(field:bar))),geotile_grid:(bounds:!n,field:bar,precision:!n,shard_size:65535,size:65535))))))&requestType=heatmap"
"rootdir/api/maps/mvt/getGridTile/{z}/{x}/{y}.pbf?geometryFieldName=bar&index=undefined&requestBody=(foobar:ES_DSL_PLACEHOLDER,params:('0':('0':index,'1':(fields:())),'1':('0':size,'1':0),'2':('0':filter,'1':!()),'3':('0':query),'4':('0':index,'1':(fields:())),'5':('0':query,'1':(language:KQL,query:'')),'6':('0':aggs,'1':())))&requestType=heatmap"
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ export class ESGeoGridSource extends AbstractESAggSource implements ITiledSingle
_addNonCompositeAggsToSearchSource(
searchSource: ISearchSource,
indexPattern: IndexPattern,
precision: number | null,
bufferedExtent?: MapExtent | null
precision: number,
bufferedExtent?: MapExtent
) {
searchSource.setField('aggs', {
[GEOTILE_GRID_AGG_NAME]: {
Expand Down Expand Up @@ -428,14 +428,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements ITiledSingle
): Promise<ITiledSingleLayerMvtParams> {
const indexPattern = await this.getIndexPattern();
const searchSource = await this.makeSearchSource(searchFilters, 0);

this._addNonCompositeAggsToSearchSource(
searchSource,
indexPattern,
null, // needs to be set server-side
null // needs to be stripped server-side
);

searchSource.setField('aggs', this.getValueAggsDsl(indexPattern));
const dsl = searchSource.getSearchRequestBody();

const risonDsl = rison.encode(dsl);
Expand Down
18 changes: 3 additions & 15 deletions x-pack/plugins/maps/server/mvt/get_grid_tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Logger } from 'src/core/server';
import type { DataRequestHandlerContext } from 'src/plugins/data/server';
import { GEOCENTROID_AGG_NAME, GEOTILE_GRID_AGG_NAME, RENDER_AS } from '../../common/constants';
import { RENDER_AS } from '../../common/constants';

function isAbortError(error: Error) {
return error.message === 'Request aborted' || error.message === 'Aborted';
Expand Down Expand Up @@ -36,27 +36,15 @@ export async function getEsGridTile({
}): Promise<Buffer | null> {
try {
const path = `/${encodeURIComponent(index)}/_mvt/${geometryFieldName}/${z}/${x}/${y}`;

const aggs: Record<string, unknown> = {};

for (const key in requestBody.aggs[GEOTILE_GRID_AGG_NAME].aggs) {
if (requestBody.aggs[GEOTILE_GRID_AGG_NAME].aggs.hasOwnProperty(key)) {
if (key !== GEOCENTROID_AGG_NAME) {
aggs[key] = requestBody.aggs[GEOTILE_GRID_AGG_NAME].aggs[key];
}
}
}

const fields = requestBody.fields;
const body = {
size: 0, // no hits
grid_precision: 7,
exact_bounds: false,
extent: 4096, // full resolution,
query: requestBody.query,
grid_type: requestType === RENDER_AS.GRID ? 'grid' : 'centroid',
aggs,
fields,
aggs: requestBody.aggs,
fields: requestBody.fields,
runtime_mappings: requestBody.runtime_mappings,
};
const tile = await context.core.elasticsearch.client.asCurrentUser.transport.request({
Expand Down

0 comments on commit 0e4e68a

Please sign in to comment.