[Maps] fix too_many_buckets_exception for top hits (#51497) (#51991)

* [Maps] fix too_many_buckets_exception for top hits

* spelling

* do not change re-fetch behavior when zooming in

* i18n cleanup

* review feedback
This commit is contained in:
Nathan Reese 2019-12-02 11:25:05 -07:00 committed by GitHub
parent 1f427b9080
commit e82405c8e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 21 deletions

View file

@ -241,10 +241,17 @@ export class ESSearchSource extends AbstractESSource {
const searchSource = await this._makeSearchSource(searchFilters, 0);
searchSource.setField('aggs', {
totalEntities: {
cardinality: {
field: topHitsSplitField,
precision_threshold: 1,
}
},
entitySplit: {
terms: {
field: topHitsSplitField,
size: ES_SIZE_LIMIT
size: ES_SIZE_LIMIT,
shard_size: ES_SIZE_LIMIT,
},
aggs: {
entityHits: {
@ -256,24 +263,29 @@ export class ESSearchSource extends AbstractESSource {
const resp = await this._runEsQuery(layerName, searchSource, registerCancelCallback, 'Elasticsearch document top hits request');
let hasTrimmedResults = false;
const allHits = [];
const entityBuckets = _.get(resp, 'aggregations.entitySplit.buckets', []);
const totalEntities = _.get(resp, 'aggregations.totalEntities.value', 0);
// can not compare entityBuckets.length to totalEntities because totalEntities is an approximate
const areEntitiesTrimmed = entityBuckets.length >= ES_SIZE_LIMIT;
let areTopHitsTrimmed = false;
entityBuckets.forEach(entityBucket => {
const total = _.get(entityBucket, 'entityHits.hits.total', 0);
const hits = _.get(entityBucket, 'entityHits.hits.hits', []);
// Reverse hits list so top documents by sort are drawn on top
allHits.push(...hits.reverse());
if (total > hits.length) {
hasTrimmedResults = true;
areTopHitsTrimmed = true;
}
});
return {
hits: allHits,
meta: {
areResultsTrimmed: hasTrimmedResults,
areResultsTrimmed: areEntitiesTrimmed || areTopHitsTrimmed, // used to force re-fetch when zooming in
areEntitiesTrimmed,
entityCount: entityBuckets.length,
totalEntities,
}
};
}
@ -459,24 +471,28 @@ export class ESSearchSource extends AbstractESSource {
}
if (this._isTopHits()) {
const entitiesFoundMsg = i18n.translate('xpack.maps.esSearch.topHitsEntitiesCountMsg', {
defaultMessage: `Found {entityCount} entities.`,
values: { entityCount: meta.entityCount }
});
if (meta.areResultsTrimmed) {
const trimmedMsg = i18n.translate('xpack.maps.esSearch.topHitsResultsTrimmedMsg', {
defaultMessage: `Results limited to most recent {topHitsSize} documents per entity.`,
values: { topHitsSize: this._descriptor.topHitsSize }
const entitiesFoundMsg = meta.areEntitiesTrimmed
? i18n.translate('xpack.maps.esSearch.topHitsResultsTrimmedMsg', {
defaultMessage: `Results limited to first {entityCount} entities of ~{totalEntities}.`,
values: {
entityCount: meta.entityCount,
totalEntities: meta.totalEntities,
}
})
: i18n.translate('xpack.maps.esSearch.topHitsEntitiesCountMsg', {
defaultMessage: `Found {entityCount} entities.`,
values: { entityCount: meta.entityCount }
});
return {
tooltipContent: `${entitiesFoundMsg} ${trimmedMsg}`,
areResultsTrimmed: false
};
}
const docsPerEntityMsg = i18n.translate('xpack.maps.esSearch.topHitsSizeMsg', {
defaultMessage: `Showing top {topHitsSize} documents per entity.`,
values: { topHitsSize: this._descriptor.topHitsSize }
});
return {
tooltipContent: entitiesFoundMsg,
areResultsTrimmed: false
tooltipContent: `${entitiesFoundMsg} ${docsPerEntityMsg}`,
// Used to show trimmed icon in legend
// user only needs to be notified of trimmed results when entities are trimmed
areResultsTrimmed: meta.areEntitiesTrimmed
};
}

View file

@ -6414,7 +6414,6 @@
"xpack.maps.esSearch.featureCountMsg": "{count} 件のドキュメントが見つかりました。",
"xpack.maps.esSearch.resultsTrimmedMsg": "結果は初めの {count} 件のドキュメントに制限されています。",
"xpack.maps.esSearch.topHitsEntitiesCountMsg": "{entityCount} 件のエントリーを発見.",
"xpack.maps.esSearch.topHitsResultsTrimmedMsg": "結果は各エンティティにつき最も最近の {topHitsSize} 件のドキュメントに制限されています。",
"xpack.maps.feature.appDescription": "Elasticsearch と Elastic Maps Service の地理空間データを閲覧します",
"xpack.maps.featureRegistry.mapsFeatureName": "Maps",
"xpack.maps.geoGrid.resolutionLabel": "グリッド解像度",

View file

@ -6355,7 +6355,6 @@
"xpack.maps.esSearch.featureCountMsg": "找到 {count} 个文档。",
"xpack.maps.esSearch.resultsTrimmedMsg": "结果仅限于前 {count} 个文档。",
"xpack.maps.esSearch.topHitsEntitiesCountMsg": "找到 {entityCount} 个实体。",
"xpack.maps.esSearch.topHitsResultsTrimmedMsg": "结果仅限于每个实体的最近 {topHitsSize} 个文档。",
"xpack.maps.feature.appDescription": "从 Elasticsearch 和 Elastic 地图服务浏览地理空间数据",
"xpack.maps.featureRegistry.mapsFeatureName": "Maps",
"xpack.maps.geoGrid.resolutionLabel": "网格分辨率",