I'd like to totally move on elasticsearch to filter elements currently handled by PostGreSQL with the PostGIS extension.
For this, I have to select every result within a given distance around (multi-)polygons.
Those polygons may be complex (hundreds of points).
I saw that a year ago, elasticsearch was not able to handle such filters.
In a year, ES has considerably evolved (including a major version), so is that kind of filtering supported by now ? If not, are there any plans ?
To explain, this is a simple usecase :
Consider this polygon as roughly describing Paris "Ile de la cité" borders:
{
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.339546203568933,
48.857710541463412
],
[
2.345168113663295,
48.856750530470009
],
[
2.350618362380806,
48.855056348509926
],
[
2.352077484084764,
48.853785674412812
],
[
2.352592468215498,
48.851611335037532
],
[
2.348730087234629,
48.852543206332619
],
[
2.343194007828603,
48.855084585345963
],
[
2.339546203568933,
48.857710541463412
]
]
]
]
}
Consider a location at the opposite of the other island (so, outside the polygon):
{
"type": "Point",
"coordinates": [
2.359378457022193,
48.850358223189644
]
}
Here are some example queries using Django ORM (I can provide the SQL equivalent but I believe this isn't relevant):
>>> Location.objects.filter(point__within=(area.polygon))
[]
>>> Location.objects.filter(point__distance_lte=(area.polygon, D(m=500)))
[]
>>> Location.objects.filter(point__distance_lte=(area.polygon, D(m=550)))
[<Location: Ile saint louis>]
The __distance
lookup uses PostGIS ST_distance_sphere
.