Problem sorting result by distance on a geoshape

As documented :

Sorting and Retrieving index Shapes

Due to the complex input structure and index representation of shapes, it is not currently possible to sort shapes or retrieve their fields directly. The geo_shape value is only retrievable through the _source field.

field Location is of type geo_shape
field Coordinates is of type geo_point

Although when I add a filter on a geoshapecircle like :

.Filter(fi => fi    
    .GeoShapeCircle(c => c
        .Name("geo_query")
        .Boost(3)
        .Field(p => p.Location)
        .Coordinates(query.Lon, query.Lat)
        .Radius($"{query.MeterDistance}m")
        .Relation(GeoShapeRelation.Intersects)
    )
)

It looks like the results are return sorted in order of proximity of the Coordinates center defined in the filter, but I didn't find anywhere to confirm or infirm this?

So for now I added a field Coordinates which is a geopoint in the index with the same coordinates as the filed Location which is a geoshape point and I am adding sort on my ES request like below but is it really needed?

.Sort(s =>
    s.GeoDistance(sd => sd
        .Ascending()
        .DistanceType(GeoDistanceType.Plane)
        .Unit(DistanceUnit.Meters)
        .Field(f => f.Coordinates)
        .Points(new GeoLocation(query.Lat, query.Lon))
        )
)

GeoShapeCircle does not order the result by distance so yes, you need to sort by GeoDistance to make sure results are ordered.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.