Skip to content

Commit

Permalink
get min values from indicies response
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Dec 18, 2019
1 parent 14e1865 commit eb168a5
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 9 deletions.
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/maps/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export const MAX_ZOOM = 24;

export const DECIMAL_DEGREES_PRECISION = 5; // meters precision
export const ZOOM_PRECISION = 2;
export const DEFAULT_ES_SIZE_LIMIT = 10000;
export const DEFAULT_MAX_RESULT_WINDOW = 10000;
export const DEFAULT_MAX_INNER_RESULT_WINDOW = 100;
export const DEFAULT_MAX_BUCKETS_LIMIT = 10000;

export const FEATURE_ID_PROPERTY_NAME = '__kbn__feature_id__';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

import { AbstractVectorSource } from '../vector_source';
import React from 'react';
import { ES_GEO_FIELD_TYPE, GEOJSON_FILE, DEFAULT_ES_SIZE_LIMIT } from '../../../../common/constants';
import {
ES_GEO_FIELD_TYPE,
GEOJSON_FILE,
DEFAULT_MAX_RESULT_WINDOW,
} from '../../../../common/constants';
import { ClientFileCreateSourceEditor } from './create_client_file_source_editor';
import { ESSearchSource } from '../es_search_source';
import uuid from 'uuid/v4';
Expand Down Expand Up @@ -82,7 +86,7 @@ export class GeojsonFileSource extends AbstractVectorSource {
addAndViewSource(null);
} else {
// Only turn on bounds filter for large doc counts
const filterByMapBounds = indexDataResp.docCount > DEFAULT_ES_SIZE_LIMIT;
const filterByMapBounds = indexDataResp.docCount > DEFAULT_MAX_RESULT_WINDOW;
const source = new ESSearchSource(
{
id: uuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { NoIndexPatternCallout } from '../../../components/no_index_pattern_call
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { kfetch } from 'ui/kfetch';
import { ES_GEO_FIELD_TYPE, GIS_API_PATH, DEFAULT_ES_SIZE_LIMIT } from '../../../../common/constants';
import {
ES_GEO_FIELD_TYPE,
GIS_API_PATH,
DEFAULT_MAX_RESULT_WINDOW,
} from '../../../../common/constants';
import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants';

import { npStart } from 'ui/new_platform';
Expand Down Expand Up @@ -96,7 +100,7 @@ export class CreateSourceEditor extends Component {
let indexHasSmallDocCount = false;
try {
const indexDocCount = await this.loadIndexDocCount(indexPattern.title);
indexHasSmallDocCount = indexDocCount <= DEFAULT_ES_SIZE_LIMIT;
indexHasSmallDocCount = indexDocCount <= DEFAULT_MAX_RESULT_WINDOW;
} catch (error) {
// retrieving index count is a nice to have and is not essential
// do not interrupt user flow if unable to retrieve count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import _ from 'lodash';
import { Schemas } from 'ui/vis/editors/default/schemas';
import { AggConfigs } from 'ui/agg_types';
import { i18n } from '@kbn/i18n';
import { DEFAULT_ES_SIZE_LIMIT, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants';
import { DEFAULT_MAX_RESULT_WINDOW, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants';
import { ESDocField } from '../fields/es_doc_field';
import { AbstractESAggSource } from './es_agg_source';

Expand Down Expand Up @@ -170,7 +170,7 @@ export class ESTermSource extends AbstractESAggSource {
schema: 'segment',
params: {
field: this._termField.getName(),
size: DEFAULT_ES_SIZE_LIMIT,
size: DEFAULT_MAX_RESULT_WINDOW,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 _ from 'lodash';
import { DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_INNER_RESULT_WINDOW } from '../../common/constants';

export function getIndexPatternSettings(indicesSettingsResp) {
let maxResultWindow = Infinity;
let maxInnerResultWindow = Infinity;
Object.values(indicesSettingsResp).forEach(indexSettings => {
const indexMaxResultWindow = _.get(
indexSettings,
'settings.index.max_result_window',
DEFAULT_MAX_RESULT_WINDOW
);
maxResultWindow = Math.min(maxResultWindow, indexMaxResultWindow);

const indexMaxInnerResultWindow = _.get(
indexSettings,
'settings.index.max_inner_result_window',
DEFAULT_MAX_INNER_RESULT_WINDOW
);
maxInnerResultWindow = Math.min(indexMaxInnerResultWindow, indexMaxResultWindow);
});

return { maxResultWindow, maxInnerResultWindow };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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 { getIndexPatternSettings } from './get_index_pattern_settings';
import { DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_INNER_RESULT_WINDOW } from '../../common/constants';

describe('max_result_window and max_inner_result_window are not set', () => {
test('Should provide default values when values not set', () => {
const indicesSettingsResp = {
kibana_sample_data_logs: {
settings: {
index: {},
},
},
};
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp);
expect(maxResultWindow).toBe(DEFAULT_MAX_RESULT_WINDOW);
expect(maxInnerResultWindow).toBe(DEFAULT_MAX_INNER_RESULT_WINDOW);
});

test('Should include default values when providing minimum values for indices in index pattern', () => {
const indicesSettingsResp = {
kibana_sample_data_logs: {
settings: {
index: {
max_result_window: '15000',
max_inner_result_window: '200',
},
},
},
kibana_sample_data_flights: {
settings: {
index: {},
},
},
};
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp);
expect(maxResultWindow).toBe(DEFAULT_MAX_RESULT_WINDOW);
expect(maxInnerResultWindow).toBe(DEFAULT_MAX_INNER_RESULT_WINDOW);
});
});

describe('max_result_window and max_inner_result_window are set', () => {
test('Should provide values from settings', () => {
const indicesSettingsResp = {
kibana_sample_data_logs: {
settings: {
index: {
max_result_window: '15000', // value is returned as string API
max_inner_result_window: '200',
},
},
},
};
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp);
expect(maxResultWindow).toBe(15000);
expect(maxInnerResultWindow).toBe(200);
});

test('Should provide minimum values for indices in index pattern', () => {
const indicesSettingsResp = {
kibana_sample_data_logs: {
settings: {
index: {
max_result_window: '15000',
max_inner_result_window: '200',
},
},
},
kibana_sample_data_flights: {
settings: {
index: {
max_result_window: '7000',
max_inner_result_window: '75',
},
},
},
};
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp);
expect(maxResultWindow).toBe(7000);
expect(maxInnerResultWindow).toBe(75);
});
});
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { EMSClient } from '@elastic/ems-client';
import fetch from 'node-fetch';
import { i18n } from '@kbn/i18n';
import { getIndexPatternSettings } from './lib/get_index_pattern_settings';

import Boom from 'boom';

Expand Down Expand Up @@ -429,8 +430,7 @@ export function initRoutes(server, licenseUid) {
const resp = await callWithRequest(request, 'indices.getSettings', {
index: query.indexPatternTitle,
});
console.log(JSON.stringify(resp, null, ' '));
return resp;
return getIndexPatternSettings(resp);
} catch (error) {
return h.response().code(400);
}
Expand Down

0 comments on commit eb168a5

Please sign in to comment.