Skip to content

Commit

Permalink
use indexSettings.maxResultWindow in documents request size
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Dec 18, 2019
1 parent eb168a5 commit 2c7fb06
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
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, registerCancelCallback) {
async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, 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, registerCancelCallback) {
async getGeoJsonWithMeta(layerName, searchFilters, prevMeta, 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 @@ -17,6 +17,8 @@ import { UpdateSourceEditor } from './update_source_editor';
import {
ES_SEARCH,
ES_GEO_FIELD_TYPE,
DEFAULT_MAX_RESULT_WINDOW,
DEFAULT_MAX_INNER_RESULT_WINDOW,
DEFAULT_MAX_BUCKETS_LIMIT,
GIS_API_PATH,
SORT_ORDER,
Expand All @@ -29,6 +31,23 @@ import { kfetch } from 'ui/kfetch';
import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants';
import { ESDocField } from '../../fields/es_doc_field';

async function loadIndexSettings(indexPatternTitle) {
try {
const indexSettings = await kfetch({
pathname: `../${GIS_API_PATH}/indexSettings`,
query: {
indexPatternTitle,
},
});
return indexSettings;
} catch (err) {
return {
maxResultWindow: DEFAULT_MAX_RESULT_WINDOW,
maxInnerResultWindow: DEFAULT_MAX_INNER_RESULT_WINDOW,
};
}
}

export class ESSearchSource extends AbstractESSource {
static type = ES_SEARCH;
static title = i18n.translate('xpack.maps.source.esSearchTitle', {
Expand Down Expand Up @@ -299,20 +318,11 @@ export class ESSearchSource extends AbstractESSource {

// searchFilters.fieldNames contains geo field and any fields needed for styling features
// Performs Elasticsearch search request being careful to pull back only required fields to minimize response size
async _getSearchHits(layerName, searchFilters, registerCancelCallback) {
async _getSearchHits(layerName, searchFilters, maxResultWindow, registerCancelCallback) {
const initialSearchContext = {
docvalue_fields: await this._getDateDocvalueFields(searchFilters.fieldNames),
};
const geoField = await this._getGeoField();
const indexPattern = await this.getIndexPattern();

const indexSettings = await kfetch({
pathname: `../${GIS_API_PATH}/indexSettings`,
query: {
indexPatternTitle: indexPattern.title,
},
});
console.log(indexSettings);

let searchSource;
if (geoField.type === ES_GEO_FIELD_TYPE.GEO_POINT) {
Expand All @@ -324,7 +334,7 @@ export class ESSearchSource extends AbstractESSource {
);
searchSource = await this._makeSearchSource(
searchFilters,
10000,
maxResultWindow,
initialSearchContext
);
searchSource.setField('source', false); // do not need anything from _source
Expand All @@ -333,7 +343,7 @@ export class ESSearchSource extends AbstractESSource {
// geo_shape fields do not support docvalue_fields yet, so still have to be pulled from _source
searchSource = await this._makeSearchSource(
searchFilters,
10000,
maxResultWindow,
initialSearchContext
);
// Setting "fields" instead of "source: { includes: []}"
Expand Down Expand Up @@ -374,12 +384,22 @@ export class ESSearchSource extends AbstractESSource {
return !!sortField && !!sortOrder;
}

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

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

const { hits, meta } = this._isTopHits()
? await this._getTopHits(layerName, searchFilters, registerCancelCallback)
: await this._getSearchHits(layerName, searchFilters, registerCancelCallback);
: await this._getSearchHits(
layerName,
searchFilters,
indexSettings.maxResultWindow,
registerCancelCallback
);

const indexPattern = await this.getIndexPattern();
const unusedMetaFields = indexPattern.metaFields.filter(metaField => {
return !['_id', '_index'].includes(metaField);
});
Expand Down Expand Up @@ -408,7 +428,7 @@ export class ESSearchSource extends AbstractESSource {

return {
data: featureCollection,
meta,
meta: { ...meta, indexSettings },
};
}

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_MAX_RESULT_WINDOW, FIELD_ORIGIN, METRIC_TYPE } from '../../../common/constants';
import { DEFAULT_MAX_BUCKETS_LIMIT, 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_MAX_RESULT_WINDOW,
size: DEFAULT_MAX_BUCKETS_LIMIT,
},
},
];
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ export class VectorLayer extends AbstractLayer {
const requestToken = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`);
const searchFilters = this._getSearchFilters(dataFilters);
const prevDataRequest = this.getSourceDataRequest();

const canSkipFetch = await canSkipSourceUpdate({
source: this._source,
prevDataRequest,
Expand All @@ -383,6 +382,7 @@ 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

0 comments on commit 2c7fb06

Please sign in to comment.