Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type VectorStyleRequestMeta = MapFilters & {

export type ESSearchSourceResponseMeta = {
areResultsTrimmed?: boolean;
resultsCount?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be optional? It should always be resp.hits.hits.length so 0 or more, or is that not right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because meta could be describing search hits or top hits. So resultsCount will not be present when using top hits.


// top hits meta
areEntitiesTrimmed?: boolean;
Expand Down
12 changes: 10 additions & 2 deletions x-pack/plugins/maps/public/actions/data_request_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import uuid from 'uuid/v4';
import { multiPoint } from '@turf/helpers';
import { FeatureCollection } from 'geojson';
import { MapStoreState } from '../reducers/store';
import { LAYER_STYLE_TYPE, LAYER_TYPE, SOURCE_DATA_REQUEST_ID } from '../../common/constants';
import {
KBN_IS_CENTROID_FEATURE,
LAYER_STYLE_TYPE,
LAYER_TYPE,
SOURCE_DATA_REQUEST_ID,
} from '../../common/constants';
import {
getDataFilters,
getDataRequestDescriptor,
Expand Down Expand Up @@ -246,7 +251,10 @@ function endDataLoad(
const layer = getLayerById(layerId, getState());
const resultMeta: ResultMeta = {};
if (layer && layer.getType() === LAYER_TYPE.VECTOR) {
resultMeta.featuresCount = features.length;
const featuresWithoutCentroids = features.filter((feature) => {
return feature.properties ? !feature.properties[KBN_IS_CENTROID_FEATURE] : true;
});
resultMeta.featuresCount = featuresWithoutCentroids.length;
}

eventHandlers.onDataLoadEnd({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import rison from 'rison-node';

import { i18n } from '@kbn/i18n';
import { IFieldType, IndexPattern } from 'src/plugins/data/public';
import { FeatureCollection, GeoJsonProperties } from 'geojson';
import { GeoJsonProperties } from 'geojson';
import { AbstractESSource } from '../es_source';
import { getHttp, getSearchService } from '../../../kibana_services';
import { addFieldToDSL, getField, hitsToGeoJson } from '../../../../common/elasticsearch_util';
Expand Down Expand Up @@ -399,6 +399,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
return {
hits: resp.hits.hits.reverse(), // Reverse hits so top documents by sort are drawn on top
meta: {
resultsCount: resp.hits.hits.length,
areResultsTrimmed: resp.hits.total > resp.hits.hits.length,
},
};
Expand Down Expand Up @@ -589,11 +590,8 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
}

getSourceTooltipContent(sourceDataRequest?: DataRequest): SourceTooltipConfig {
const featureCollection: FeatureCollection | null = sourceDataRequest
? (sourceDataRequest.getData() as FeatureCollection)
: null;
const meta = sourceDataRequest ? sourceDataRequest.getMeta() : null;
if (!featureCollection || !meta) {
if (!meta) {
// no tooltip content needed when there is no feature collection or meta
return {
tooltipContent: null,
Expand Down Expand Up @@ -631,7 +629,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
return {
tooltipContent: i18n.translate('xpack.maps.esSearch.resultsTrimmedMsg', {
defaultMessage: `Results limited to first {count} documents.`,
values: { count: featureCollection.features.length },
values: { count: meta.resultsCount },
}),
areResultsTrimmed: true,
};
Expand All @@ -640,7 +638,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
return {
tooltipContent: i18n.translate('xpack.maps.esSearch.featureCountMsg', {
defaultMessage: `Found {count} documents.`,
values: { count: featureCollection.features.length },
values: { count: meta.resultsCount },
}),
areResultsTrimmed: false,
};
Expand Down