How do I create a spacial index in neo4j using onl

2020-04-28 21:28发布

问题:

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?

回答1:

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.