1

I want to play with neo4j and spacial indexes. I can't find any documentation that demonstrates how to do this through cypher, only through the REST API.

Is it possibly to create spacial indexes through Cypher, say in the neo4j web console?

Dr Joe
  • 718
  • 5
  • 19

1 Answers1

4

There is currently no way to create a spatial index using Cypher. You can either use java API or a REST call, see docs at http://neo4j-contrib.github.io/spatial/#rest-api-create-a-spatial-index for details. Since Neo4j browser allows to send HTTP POST you can type there:

:POST /db/data/index/node {"name":"geom", "config": 
  {"provider":"spatial", "geometry_type":"point", "lat":"lat", "lon":"lon"}
}

Alternatively you can use the index command within neo4j-shell.

Update for Neo4j 3.0

Neo4j Spatial for 3.0 provides stored procedures to manage the spatial index - and therefore everything can be done through cypher. See https://github.com/neo4j-contrib/spatial/blob/master/src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java. Note: this version is not yet released, so you have to build from source yourself.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • Does this index all nodes that have lon and lat properties, or do I need to do something to apply it to just :PostCode's say. (Sorry! Newbie questions!) – Dr Joe Oct 26 '14 at 08:08
  • 1
    Spatial indexes are manual indexes and therefore you need to manually add the nodes to the index. There is a REST call for this, see http://neo4j.com/docs/stable/rest-api-indexes.html#rest-api-add-node-to-index – Stefan Armbruster Oct 26 '14 at 09:58
  • I'm having trouble creating a spatial index using the java API backed by a REST database connection http://stackoverflow.com/questions/26602540 – Dr Joe Oct 28 '14 at 12:23
  • No scrub that. It's ok :) I can create an index over REST in exactly the way you suggest: `graphDb.index().forNodes( "points", ["provider": "spatial", "geometry_type": "point", "lat": "lat", "lon":"lon"])` – Dr Joe Oct 28 '14 at 12:54