dgraph-io/dgraph · error
Require a point for a within query.
Error message
Require a point for a within query.
What it means
Thrown by queryTokensGeo when a QueryTypeNear query is issued with a nil point. A near query needs a center point around which a loop of the given radius is formed; with pt == nil there is no center to search around.
Source
Thrown at types/geofilter.go:189
switch qt {
case QueryTypeWithin:
// For a within query we only need to look at the objects whose parents match our cover.
// So we take our cover and prefix with the parentPrefix to look in the index.
if len(loops) == 0 {
return nil, nil, errors.Errorf("Require a polygon for within query")
}
toks := createTokens(cover, parentPrefix)
return toks, &GeoQueryData{loops: loops, qtype: qt}, nil
case QueryTypeContains:
// For a contains query, we only need to look at the objects whose cover matches our
// parents. So we take our parents and prefix with the coverPrefix to look in the index.
return createTokens(parents, coverPrefix), &GeoQueryData{pt: pt, loops: loops, qtype: qt}, nil
case QueryTypeNear:
if pt == nil {
return []string{}, nil, errors.Errorf("Require a point for a within query.")
}
// A near query is the same as the intersects query. We form a loop with the given point and
// the radius and then see what all does it intersect with.
toks := parentCoverTokens(parents, cover)
return toks, &GeoQueryData{loops: loops, qtype: QueryTypeIntersects}, nil
case QueryTypeIntersects:
// An intersects query is as the name suggests all the entities which intersect with the
// given region. So we look at all the objects whose parents match our cover as well as
// all the objects whose cover matches our parents.
if len(loops) == 0 {
return nil, nil, errors.Errorf("Require a polygon for intersects query")
}
toks := parentCoverTokens(parents, cover)
return toks, &GeoQueryData{loops: loops, qtype: qt}, nil
default:
return nil, nil, errors.Errorf("Unknown query type")View on GitHub (pinned to 759e242be6)
Solutions
- Populate the point (longitude, latitude) before issuing a near query
- Validate pt != nil before calling queryTokensGeo with QueryTypeNear
- Use QueryTypeWithin with a polygon if you actually have a region, not a point
Example fix
// before
query := dgraph.Query{Type: dgraph.QueryTypeNear} // pt never set
// after
query := dgraph.Query{Type: dgraph.QueryTypeNear, Point: &geom.Point{X: -122.4, Y: 37.7}} Defensive patterns
Strategy: validation
Validate before calling
if qt == QueryTypeNear && pt == nil {
return errors.New("near query requires a point")
} Type guard
func isPointSet(pt *geom.Point) bool { return pt != nil } Try / catch
toks, data, err := types.GetGeoTokens(qt, pt, loops, cover, parents)
if err != nil && strings.Contains(err.Error(), "Require a point") {
// prompt user for coordinates or default to a configured location
} Prevention
- Require coordinates in near-query payloads before dispatch
- Provide sensible default locations server-side when point is absent
- Distinguish near (point) vs within/intersects (polygon) in query schema validation
When it happens
Trigger: Calling GetGeoTokens/queryTokens with QueryTypeNear and the point (pt) argument set to nil, e.g. a near filter where the coordinates field was missing or not decoded.
Common situations: A near query built from JSON where 'coordinates' is absent, or code paths that reuse an intersects-style filter for near without populating the point.
Related errors
- Require a polygon for within query
- Require a polygon for intersects query
- Invalid compare function %q
- expand() not allowed inside shortest
- Node with count cannot have child attributes
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/1fb1edb9d616b9be.
Report an issue: GitHub.