Adding existing nodes to a spatial index (using spring data)

306 views Asked by At

I've got an existing project for which I want to build a spatial index.

I can created a spatial index for a pre-existing Neo4j database managed by spring-data-neo4j on the existing database by adding @Index to the domain class:

@NodeEntity
class Junction {
    @GraphId Long id;
    @Indexed(indexType = IndexType.POINT, indexName = "junctionLocations") Point wkt;
}

I've populated the wkt's for all the existing nodes in the graphdb, but I can't work out how to add the existing nodes to the new spatial index. It's not possible for me to rebuild the graph from scratch because it already has many layers connected to these existing nodes through pre-existing relationships.

I've been through the unit tests for spatial and for SDN, but none of them document how to add an existing node to a new index. I also can't work out in the code where nodes are added to the index defined by SDN.

Can anyone help please?

2

There are 2 answers

0
Dr Joe On BEST ANSWER

I forgot that this question hadn't been answered.

The answer was simple. Every time a node is saved in Spring-data-neo4j, it is added to any defined indexes at that point. So the solution was just to iterate over all the pre-existing nodes and re-save them.

Problem solved.

1
Jim Biard On

I'm not a Spring kinda guy, but here are some answers to the general question that may be of help.