1

I am trying to search the Azure Search Index for documents that are not just within x km of the search reference point but also where the document + y km is within x km of the search reference. y is a field on the document so it will be different for each document in the index.

Ben Edge
  • 314
  • 1
  • 4
  • 5

1 Answers1

2

To find filter based on the distance between a reference point and a point given by a field in the document, you can use the geo.distance function in your $filter query. For instance if your geo point was in the field "location", you could filter to all results that are within 10km of that point with the following clause:

$filter=geo.distance(location, geography'POINT(-122.131577 47.678581)') le 10  

Azure Search also supports geo filtering by specifying a bounding polygon using the geo.intersects function:

$filter=geo.intersects(location, geography'POLYGON((-122.031577 47.578581, -122.031577 47.678581, -122.131577 47.678581, -122.031577 47.578581))')

If you're looking for something like geo.distance(...) lt someOtherField that is currently unsupported.

From your question it sounds like you have a field in the document, and a static point that you'd like to check against, filtering by all documents that are within a certain range. This should be achievable with geo.distance. If this doesn't cover your scenario, can you provide more details and perhaps a concrete example of the problem you're trying to solve?

You can find more information about odata filtering using geo.distance and geo.intersects in the Azure Search OData syntax documentation

Evan Boyle
  • 41
  • 2
  • 2
    Thanks @EvanBoyle. What we essentially need to do is this: `$filter=geo.distance(location, geography'POINT(-122.131577 47.678581)') le field_value` where field_value is an integer field on each document. I also came to the conclusion this wasn't supported, however I am hoping there is a creative way to deal the the use case. The scenario is, we are looking for people who are willing to travel up to and including the reference point (constant) we are searching for. Make sense? – Ben Edge Jun 29 '17 at 16:27