Open mtzonev opened 4 years ago
Hi @mtzonev,
This issue is reproducible as you described.
The index is only considered when the indexed field is supplied as second argument
However, this is also the behavior that our documentation is currently stating:
The first parameter of GEO_CONTAINS must be a polygon. Other types are not valid. The second parameter must contain the document field on which the index was created.
I agree that your use case is sensible and we will keep this issue open as a feature request. I can't provide an ETA for this feature though.
@maxkernbach I see. Thank you for that. I guess I'll have to search for alternatives until this hopefully becomes supported natively.
My Environment
Component, Query & Data
Affected feature:
Geo-spatial index of geoJson type.
AQL query:
AQL explain:
Dataset:
Single collection in the database. For the sake of testing the query above a single vertex is enough:
https://gist.github.com/mtzonev/4bfc808684280595ed399c29b381c29a
Size of your Dataset on disk:
The full dump of the database is around 40MB.
Steps to reproduce
timezones
collection.ensureIndex({ type: "geo", fields: [ "geojson.geometry" ], geoJson:true })
Problem:
The index on the geometry field is not used when the field is supplied as the first argument of the GEO_CONTAINS function.
Expected result:
The geospatial index to be used regardless of position on which the indexed field is passed to the GEO functions. The function does work like that - the point is correctly placed within the Polygon/MultiPolygon from the field but the index is never made use of which results in a very slow query with the full collection.
NOTE: The index is only considered when the indexed field is supplied as second argument (meaning I can only check whether my stored data is contained in another arbitrary geometry object but I need it the other way around). I believe my use-case is perfectly reasonable and viable and I can't see a valid reason why it wouldn't work.