Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] use pre-indexed shapes in shape filters when shape is stored in elasticsearch #47171

Merged
merged 3 commits into from
Oct 3, 2019
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 @@ -197,6 +197,7 @@ export class GeometryFilterForm extends Component {
fill
onClick={this._onSubmit}
isDisabled={!this.state.geometryLabel || !this.state.geoFieldTag}
isLoading={this.props.isLoading}
>
{this.props.buttonLabel}
</EuiButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,46 @@ import { GeometryFilterForm } from '../../components/geometry_filter_form';

export class FeatureGeometryFilterForm extends Component {

_createFilter = ({ geometryLabel, indexPatternId, geoFieldName, geoFieldType, relation }) => {
state = {
isLoading: false,
}

componentDidMount() {
this._isMounted = true;
}

componentWillUnmount() {
this._isMounted = false;
}

_loadPreIndexedShape = async () => {
this.setState({
isLoading: true,
});

let preIndexedShape;
try {
preIndexedShape = await this.props.loadPreIndexedShape();
} catch (err) {
// ignore error, just fall back to using geometry if preIndexedShape can not be fetched
}

if (this._isMounted) {
this.setState({ isLoading: false });
}

return preIndexedShape;
}

_createFilter = async ({ geometryLabel, indexPatternId, geoFieldName, geoFieldType, relation }) => {
const preIndexedShape = await this._loadPreIndexedShape();
if (!this._isMounted) {
// do not create filter if component is unmounted
return;
}

const filter = createSpatialFilterWithGeometry({
preIndexedShape,
geometry: this.props.geometry,
geometryLabel,
indexPatternId,
Expand Down Expand Up @@ -65,6 +103,7 @@ export class FeatureGeometryFilterForm extends Component {
onSubmit={this._createFilter}
isFilterGeometryClosed={this.props.geometry.type !== GEO_JSON_TYPE.LINE_STRING
&& this.props.geometry.type !== GEO_JSON_TYPE.MULTI_LINE_STRING}
isLoading={this.state.isLoading}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ export class FeatureTooltip extends React.Component {
);
}

_loadCurrentFeaturePreIndexedShape = () => {
const filteredFeatures = this._filterFeatures();
const currentFeature = filteredFeatures[this.state.pageNumber];
return this.props.loadPreIndexedShape({
layerId: currentFeature.layerId,
featureId: currentFeature.id
});
}

render() {
const filteredFeatures = this._filterFeatures();
const currentFeature = filteredFeatures[this.state.pageNumber];
Expand All @@ -355,6 +364,7 @@ export class FeatureTooltip extends React.Component {
geometry={currentFeatureGeometry}
geoFields={filteredGeoFields}
addFilters={this.props.addFilters}
loadPreIndexedShape={this._loadCurrentFeaturePreIndexedShape}
/>
);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class TooltipControl extends React.Component {
if (!tooltipLayer) {
return null;
}

const targetFeature = tooltipLayer.getFeatureById(featureId);
if (!targetFeature) {
return null;
Expand All @@ -264,13 +265,28 @@ export class TooltipControl extends React.Component {
if (!tooltipLayer) {
return [];
}

const targetFeature = tooltipLayer.getFeatureById(featureId);
if (!targetFeature) {
return [];
}
return await tooltipLayer.getPropertiesForTooltip(targetFeature.properties);
};

_loadPreIndexedShape = async ({ layerId, featureId }) => {
const tooltipLayer = this._findLayerById(layerId);
if (!tooltipLayer) {
return null;
}

const targetFeature = tooltipLayer.getFeatureById(featureId);
if (!targetFeature) {
return null;
}

return await tooltipLayer.getSource().getPreIndexedShape(targetFeature.properties);
};

_findLayerById = (layerId) => {
return this.props.layerList.find(layer => {
return layer.getId() === layerId;
Expand Down Expand Up @@ -308,6 +324,7 @@ export class TooltipControl extends React.Component {
anchorLocation={this.props.tooltipState.location}
findLayerById={this._findLayerById}
geoFields={this.props.geoFields}
loadPreIndexedShape={this._loadPreIndexedShape}
/>
</EuiText>
);
Expand Down
16 changes: 12 additions & 4 deletions x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export function createSpatialFilterWithGeometry(options) {
}

function createGeometryFilterWithMeta({
preIndexedShape,
geometry,
geometryLabel,
indexPatternId,
Expand All @@ -320,14 +321,21 @@ function createGeometryFilterWithMeta({
};

if (geoFieldType === ES_GEO_FIELD_TYPE.GEO_SHAPE) {
const shapeQuery = {
relation
};

if (preIndexedShape) {
shapeQuery.indexed_shape = preIndexedShape;
} else {
shapeQuery.shape = geometry;
}

return {
meta,
geo_shape: {
ignore_unmapped: true,
[geoFieldName]: {
shape: geometry,
relation
}
[geoFieldName]: shapeQuery
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class ESSearchSource extends AbstractESSource {

const indexPattern = await this._getIndexPattern();
const unusedMetaFields = indexPattern.metaFields.filter(metaField => {
return metaField !== '_id';
return !['_id', '_index'].includes(metaField);
});
const flattenHit = hit => {
const properties = indexPattern.flattenHit(hit);
Expand Down Expand Up @@ -412,4 +412,14 @@ export class ESSearchSource extends AbstractESSource {
topHitsSize: this._descriptor.topHitsSize,
};
}

async getPreIndexedShape(properties) {
const geoField = await this._getGeoField();

return {
index: properties._index, // Can not use index pattern title because it may reference many indices
id: properties._id,
path: geoField.name,
};
}
}
5 changes: 5 additions & 0 deletions x-pack/legacy/plugins/maps/public/layers/sources/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export class AbstractSource {
supportsElasticsearchFilters() {
return false;
}

// Returns geo_shape indexed_shape context for spatial quering by pre-indexed shapes
async getPreIndexedShape(/* properties */) {
return null;
}
}