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] get max_result_window and max_inner_result_window from index settings #53500

Merged
merged 19 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/maps/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const APP_ICON = 'gisApp';

export const MAP_APP_PATH = `app/${APP_ID}`;
export const GIS_API_PATH = `api/${APP_ID}`;
export const INDEX_SETTINGS_API_PATH = `${GIS_API_PATH}/indexSettings`;

export const MAP_BASE_URL = `/${MAP_APP_PATH}#/${MAP_SAVED_OBJECT_TYPE}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
);
}

async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, registerCancelCallback) {
async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) {
const indexPattern = await this.getIndexPattern();
const searchSource = await this._makeSearchSource(searchFilters, 0);
const aggConfigs = new AggConfigs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class ESPewPewSource extends AbstractESAggSource {
return Math.min(targetGeotileLevel, MAX_GEOTILE_LEVEL);
}

async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, registerCancelCallback) {
async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) {
const indexPattern = await this.getIndexPattern();
const metricAggConfigs = this.createMetricAggConfigs();
const aggConfigs = new AggConfigs(indexPattern, metricAggConfigs, aggSchemas.all);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,10 @@ export class ESSearchSource extends AbstractESSource {
return !!sortField && !!sortOrder;
}

async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, registerCancelCallback) {
async getGeoJsonWithMeta(layerName, searchFilters, registerCancelCallback) {
const indexPattern = await this.getIndexPattern();

const indexSettings = prevMeta.indexSettings
? prevMeta.indexSettings
: await loadIndexSettings(indexPattern.title);
const indexSettings = await loadIndexSettings(indexPattern.title);

const { hits, meta } = this._isTopHits()
? await this._getTopHits(layerName, searchFilters, registerCancelCallback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@
import {
DEFAULT_MAX_RESULT_WINDOW,
DEFAULT_MAX_INNER_RESULT_WINDOW,
GIS_API_PATH,
INDEX_SETTINGS_API_PATH,
} from '../../../../common/constants';
import { kfetch } from 'ui/kfetch';

const indexSettings = new Map();

export async function loadIndexSettings(indexPatternTitle) {
if (indexSettings.has(indexPatternTitle)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call caching the promise, not the result.

return indexSettings.get(indexPatternTitle);
}

const fetchPromise = fetchIndexSettings(indexPatternTitle);
indexSettings.set(indexPatternTitle, fetchPromise);
return fetchPromise;
}

async function fetchIndexSettings(indexPatternTitle) {
try {
const indexSettings = await kfetch({
pathname: `../${GIS_API_PATH}/indexSettings`,
pathname: `../${INDEX_SETTINGS_API_PATH}`,
query: {
indexPatternTitle,
},
});
return indexSettings;
} catch (err) {
nreese marked this conversation as resolved.
Show resolved Hide resolved
console.warn(`Unable to fetch index settings for index pattern '${indexPatternTitle}'.
Ensure user has 'view_index_metadata' role.`);
return {
maxResultWindow: DEFAULT_MAX_RESULT_WINDOW,
maxInnerResultWindow: DEFAULT_MAX_INNER_RESULT_WINDOW,
Expand Down
1 change: 0 additions & 1 deletion x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ export class VectorLayer extends AbstractLayer {
const { data: sourceFeatureCollection, meta } = await this._source.getGeoJsonWithMeta(
layerName,
searchFilters,
prevDataRequest ? prevDataRequest.getMeta() : {},
registerCancelCallback.bind(null, requestToken)
);
const layerFeatureCollection = assignFeatureIds(sourceFeatureCollection);
Expand Down
8 changes: 7 additions & 1 deletion x-pack/legacy/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EMS_TILES_VECTOR_TILE_PATH,
GIS_API_PATH,
EMS_SPRITES_PATH,
INDEX_SETTINGS_API_PATH,
} from '../common/constants';
import { EMSClient } from '@elastic/ems-client';
import fetch from 'node-fetch';
Expand Down Expand Up @@ -417,11 +418,12 @@ export function initRoutes(server, licenseUid) {

server.route({
method: 'GET',
path: `${ROOT}/indexSettings`,
path: `/${INDEX_SETTINGS_API_PATH}`,
handler: async (request, h) => {
const { server, query } = request;

if (!query.indexPatternTitle) {
server.log('warning', `Required query parameter 'indexPatternTitle' not provided.`);
return h.response().code(400);
}

Expand All @@ -432,6 +434,10 @@ export function initRoutes(server, licenseUid) {
});
return getIndexPatternSettings(resp);
} catch (error) {
nreese marked this conversation as resolved.
Show resolved Hide resolved
server.log(
'warning',
`Cannot load index settings for index pattern '${query.indexPatternTitle}', error: ${error.message}.`
);
return h.response().code(400);
}
},
Expand Down