Related: Relation, Schema, Relation Guide, Cookbook Geo search lets you filter, sort, and boost documents by geographic location using Typesense’s nativeDocumentation Index
Fetch the complete documentation index at: https://nikita-shkoda.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
geopoint type. All geo chainers are immutable, copy-on-write, and composable with existing where / order chainers.
Schema setup
Declare a:geopoint attribute on your model. Typesense expects the value as a [lat, lng] array.
[:geopoint] for an array of geopoints:
where_geo — geo filtering
Filter results by geographic proximity (radius) or containment (polygon). Compiles to Typesensefilter_by.
Radius filter
lat/lng: reference point coordinatesradius: string with unit —"10 km"or"5 mi"
Polygon filter
- Requires 3 or more
[lat, lng]points - Points define the polygon boundary; Typesense returns documents inside it
Chaining with where
where and where_geo calls compose with AND semantics.
Validation
- Field must be declared as
:geopointor[:geopoint] - Coordinates are validated: lat in
[-90, 90], lng in[-180, 180] - Radius format must match
"<number> km"or"<number> mi" within_radius:andwithin_polygon:are mutually exclusive- Polygon must have at least 3 points, each as
[lat, lng]
order_geo — distance sorting
Sort results by distance from a reference point. Compiles to Typesensesort_by with the geopoint distance syntax.
:asc (nearest first). Use direction: :desc for farthest first.
Advanced options
exclude_radius: exclude results within this distance from distance scoringprecision: bucket precision for distance sort
Chaining with order
order_eval — conditional sort expressions
Sort by a Typesense_eval() expression. Useful for boosting documents that match a condition (e.g., inside a map viewport polygon) without filtering them out.
Simple expression
_eval(location:(54.72,25.35, ...)):desc
Default direction is :desc (matching documents first).
Weighted multi-expression
_eval([ (location:(...)):3, (rating:>4.5):1 ]):desc
Viewport boost pattern
The canonical map search pattern: boost documents in the visible viewport, then sort by distance as a tiebreaker.geo_distance_meters — distance on results
Whenorder_geo is used, Typesense includes distance metadata on each hit. The gem exposes this via the geo_distance_meters method on hydrated result objects.
- Returns a
Hashmapping field name to distance in meters, e.g.{ "location" => 1234 } - Only present when the response includes
geo_distance_meters(i.e., when a geo sort is active) - Works for both flat and grouped results
Full example
Troubleshooting
- “field must be declared as :geopoint”: ensure the attribute is declared with
:geopointtype in your model - No
geo_distance_meterson hits: this metadata is only present whensort_byincludes a geopoint distance sort — useorder_geo - Invalid radius format: use a string like
"10 km"or"5 mi"— bare numbers or other units are rejected