Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[maps] ignore indices without geometry field in vector tile requests #171472

Merged
merged 10 commits into from Nov 22, 2023
Expand Up @@ -27,6 +27,13 @@ import { LICENSED_FEATURES } from '../../../licensed_features';
jest.mock('../../../kibana_services');

export class MockSearchSource {
getField(fieldName: string) {
if (fieldName === 'filter') {
return [];
}

throw new Error(`Unsupported search source field: ${fieldName}`);
}
setField = jest.fn();
setParent() {}
getSearchRequestBody() {
Expand Down Expand Up @@ -324,7 +331,7 @@ describe('ESGeoGridSource', () => {
index: 'foo-*',
renderAs: 'heatmap',
requestBody:
"(fields:('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':())))",
"(fields:('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':()),'7':('0':filter,'1':!((meta:(),query:(exists:(field:bar)))))))",
token: '1234',
});
});
Expand Down
Expand Up @@ -21,6 +21,7 @@ import { DataView } from '@kbn/data-plugin/common';
import { Adapters } from '@kbn/inspector-plugin/common/adapters';
import { ACTION_GLOBAL_APPLY_FILTER } from '@kbn/unified-search-plugin/public';
import { getTileUrlParams } from '@kbn/maps-vector-tile-utils';
import { type Filter, buildExistsFilter } from '@kbn/es-query';
import { makeESBbox } from '../../../../common/elasticsearch_util';
import { convertCompositeRespToGeoJson, convertRegularRespToGeoJson } from './convert_to_geojson';
import { UpdateSourceEditor } from './update_source_editor';
Expand Down Expand Up @@ -553,6 +554,11 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
const dataView = await this.getIndexPattern();
const searchSource = await this.makeSearchSource(requestMeta, 0);
searchSource.setField('aggs', this.getValueAggsDsl(dataView));
// Filter out documents without geo fields for broad index-pattern support
searchSource.setField('filter', [
...(searchSource.getField('filter') as Filter[]),
buildExistsFilter({ name: this._descriptor.geoField, type: 'geo_point' }, dataView),
]);

const mvtUrlServicePath = getHttp().basePath.prepend(
`${MVT_GETGRIDTILE_API_PATH}/{z}/{x}/{y}.pbf`
Expand Down
Expand Up @@ -53,6 +53,13 @@ describe('ESSearchSource', () => {

beforeEach(async () => {
const mockSearchSource = {
getField: (fieldName: string) => {
if (fieldName === 'filter') {
return [];
}

throw new Error(`Unsupported search source field: ${fieldName}`);
},
setField: jest.fn(),
getSearchRequestBody() {
return {
Expand Down Expand Up @@ -131,7 +138,7 @@ describe('ESSearchSource', () => {
hasLabels: 'false',
index: 'foobar-title-*',
requestBody:
"(fields:('0':('0':index,'1':(fields:(),title:'foobar-title-*')),'1':('0':size,'1':1000),'2':('0':filter,'1':!()),'3':('0':query),'4':('0':index,'1':(fields:(),title:'foobar-title-*')),'5':('0':query,'1':(language:KQL,query:'tooltipField: foobar')),'6':('0':fieldsFromSource,'1':!(_id)),'7':('0':source,'1':!f),'8':('0':fields,'1':!(tooltipField,styleField))))",
"(fields:('0':('0':index,'1':(fields:(),title:'foobar-title-*')),'1':('0':size,'1':1000),'2':('0':filter,'1':!()),'3':('0':query),'4':('0':index,'1':(fields:(),title:'foobar-title-*')),'5':('0':query,'1':(language:KQL,query:'tooltipField: foobar')),'6':('0':fieldsFromSource,'1':!(_id)),'7':('0':source,'1':!f),'8':('0':fields,'1':!(tooltipField,styleField)),'9':('0':filter,'1':!((meta:(),query:(exists:(field:bar)))))))",
token: '1234',
});
});
Expand Down
Expand Up @@ -12,7 +12,7 @@ import { i18n } from '@kbn/i18n';
import type { SearchResponseWarning } from '@kbn/search-response-warnings';
import { GeoJsonProperties, Geometry, Position } from 'geojson';
import type { KibanaExecutionContext } from '@kbn/core/public';
import { type Filter, buildPhraseFilter, type TimeRange } from '@kbn/es-query';
import { type Filter, buildExistsFilter, buildPhraseFilter, type TimeRange } from '@kbn/es-query';
import type { DataViewField, DataView } from '@kbn/data-plugin/common';
import { lastValueFrom } from 'rxjs';
import { Adapters } from '@kbn/inspector-plugin/common/adapters';
Expand Down Expand Up @@ -923,6 +923,12 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
})
);

// Filter out documents without geo fields to avoid shard failures for indices without geo fields
searchSource.setField('filter', [
...(searchSource.getField('filter') as Filter[]),
buildExistsFilter({ name: this._descriptor.geoField, type: 'geo_point' }, dataView),
]);

const mvtUrlServicePath = getHttp().basePath.prepend(`${MVT_GETTILE_API_PATH}/{z}/{x}/{y}.pbf`);

const tileUrlParams = getTileUrlParams({
Expand Down
Expand Up @@ -53,7 +53,7 @@ export default function ({ getPageObjects, getService }) {
index: 'logstash-*',
gridPrecision: '8',
renderAs: 'grid',
requestBody: `(aggs:(max_of_bytes:(max:(field:bytes))),fields:!((field:'@timestamp',format:date_time),(field:'relatedContent.article:modified_time',format:date_time),(field:'relatedContent.article:published_time',format:date_time),(field:utc_time,format:date_time)),query:(bool:(filter:!((range:('@timestamp':(format:strict_date_optional_time,gte:'2015-09-20T00:00:00.000Z',lte:'2015-09-20T01:00:00.000Z')))),must:!(),must_not:!(),should:!())),runtime_mappings:())`,
requestBody: `(aggs:(max_of_bytes:(max:(field:bytes))),fields:!((field:'@timestamp',format:date_time),(field:'relatedContent.article:modified_time',format:date_time),(field:'relatedContent.article:published_time',format:date_time),(field:utc_time,format:date_time)),query:(bool:(filter:!((range:('@timestamp':(format:strict_date_optional_time,gte:'2015-09-20T00:00:00.000Z',lte:'2015-09-20T01:00:00.000Z'))),(exists:(field:geo.coordinates))),must:!(),must_not:!(),should:!())),runtime_mappings:())`,
});

//Should correctly load meta for style-rule (sigma is set to 1, opacity to 1)
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/maps/group4/mvt_scaling.js
Expand Up @@ -55,7 +55,7 @@ export default function ({ getPageObjects, getService }) {
hasLabels: 'false',
index: 'geo_shapes*',
requestBody:
'(fields:!(prop1),query:(bool:(filter:!(),must:!(),must_not:!(),should:!())),runtime_mappings:(),size:10001)',
'(fields:!(prop1),query:(bool:(filter:!((exists:(field:geometry))),must:!(),must_not:!(),should:!())),runtime_mappings:(),size:10001)',
});
});

Expand Down