UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Typed Graph
    • Open Graph
    • Graph Sharding and Storage
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • SET
    • REMOVE
    • DELETE
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Scalar Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Label Functions
    • Record Functions
    • Table Functions
  • Operators
  • Predicates
    • CASE
    • NULLIF
    • COALESCE
    • LET Value Expression
    • Value Query Expression
    • Index
    • Full-text Index
    • Vector Index
    • Spatial Index
    • Overview
    • Managing HDC Graphs
    • HDC Graph Queries
  • Transaction
  • Trigger
  • Stored Procedure
    • Process
    • Session
    • Job
    • Execution Plan
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • Access Control
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Query Acceleration

Spatial Index

Overview

A spatial index enables efficient radius queries on POINT and POINT3D properties using geohash-based encoding. Instead of scanning all entities and computing distances, the spatial index narrows the search to a small set of candidates within the relevant geographic area.

Spatial indexes support:

  • POINT: WGS84 geographic coordinates (latitude, longitude) for 2D spatial queries.
  • POINT3D: 3D Cartesian coordinates (x, y, z) for 3D spatial queries.

Showing Spatial Indexes

Spatial indexes appear in the standard index listing:

GQL
SHOW NODE INDEX
SHOW EDGE INDEX

Spatial indexes are displayed with type SPATIAL and the expression function geohash.

Creating a Spatial Index

GQL
CREATE SPATIAL INDEX <indexName> ON NODE <schemaName> (<propertyName>)
CREATE SPATIAL INDEX <indexName> ON EDGE <schemaName> (<propertyName>)

The property must be of type POINT or POINT3D. Attempting to create a spatial index on other property types returns an error.

To create a spatial index on a POINT property:

GQL
CREATE SPATIAL INDEX idx_location ON NODE Station (location)

To create a spatial index on a POINT3D property:

GQL
CREATE SPATIAL INDEX idx_position ON NODE Sensor (position)

To create a spatial index on an edge property:

GQL
CREATE SPATIAL INDEX idx_route ON EDGE Route (waypoint)

Using IF NOT EXISTS

GQL
CREATE SPATIAL INDEX idx_location ON NODE Station (location) IF NOT EXISTS

Dropping a Spatial Index

GQL
DROP NODE SPATIAL INDEX idx_location
DROP EDGE SPATIAL INDEX idx_route

Using IF EXISTS

GQL
DROP NODE SPATIAL INDEX idx_location IF EXISTS
DROP EDGE SPATIAL INDEX idx_route IF EXISTS

Using Spatial Indexes

When a spatial index exists on a property, distance() queries with < or <= operators are automatically optimized to use spatial index range scans instead of full table scans.

Optimized Query Patterns

Basic radius query:

GQL
MATCH (n:Station)
WHERE distance(n.location, point({latitude: 31.23, longitude: 121.47})) < 50000
RETURN n.name

Less-than-or-equal radius query:

GQL
MATCH (n:Station)
WHERE distance(n.location, point({latitude: 31.23, longitude: 121.47})) <= 50000
RETURN n.name

Reversed argument order (also optimized):

GQL
MATCH (n:Station)
WHERE distance(point({latitude: 31.23, longitude: 121.47}), n.location) < 50000
RETURN n.name

Combined with other conditions:

GQL
MATCH (n:Station)
WHERE distance(n.location, point({latitude: 31.23, longitude: 121.47})) < 50000
  AND n.name STARTS WITH 'S'
RETURN n.name

3D distance query:

GQL
MATCH (n:Sensor)
WHERE distance(n.position, point3d({x: 115.0, y: 215.0, z: 65.0})) < 20
RETURN n.name

Use EXPLAIN to verify that a spatial index is being used:

GQL
EXPLAIN MATCH (n:Station)
WHERE distance(n.location, point({latitude: 31.23, longitude: 121.47})) < 50000
RETURN n

The execution plan will show SPATIAL INDEX SCAN when the spatial index is used.

Not Optimized

The following patterns do not use spatial indexes and result in a full scan:

  • Greater-than comparisons: distance(...) > 50000
  • Expressions that modify the distance: distance(...) + 100 < 50000

DML Auto-Maintenance

Spatial indexes are automatically maintained when data changes:

OperationBehavior
INSERTNew geohash key added to the index.
SETOld key removed, new key added.
DELETEKey removed from the index.
SET to NULLOld key removed from the index.

Entities with NULL spatial properties are not indexed.