mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Maps] fix too_many_buckets_exception for top hits (#51497)
* [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:
parent
b3cf311808
commit
d2846b618d
3 changed files with 35 additions and 21 deletions
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6406,7 +6406,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": "グリッド解像度",
|
||||
|
|
|
@ -6408,7 +6408,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": "网格分辨率",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue