Search Azure Search Index for documents within x k

2019-09-14 23:18发布

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.

1条回答
forever°为你锁心
2楼-- · 2019-09-14 23:37

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

查看更多
登录 后发表回答