2

I am using Neo4j-Spatial with Spring data in a Play!Framework application.

I have a @NodeEntity of type User which I want to store in the database as well as a spatial index for location based queries.

The examples that I have seen create a Node using the GraphDatabaseService:

Node stadiumNode = graphDatabaseService.createNode();

and then add this Node to the spatial index:

Index<Node> index = graphDatabaseService.index().forNodes(indexLayerName, config)`;
stadiumNode.setProperty("wkt", String.format("POINT(%s %s)", lat, lon)); 
index.add(stadiumNode, "dummyA", "dummyB");

However, the Node does not have a specific type (such as User) associated with it. In order to do that, I have to first create interface UserRepository extends GraphRepository<User> :

@Autowired
private UserRepository userRepository;

and then add the User nodeEntity to the repository:

User user = new User();
userRepository.save(user);

However, this creates 3 nodes (1 in the spatial index RTree, and 2 in the neo4j graph). What is the correct way of doing this? I just want 2 nodes:

  1. One node of type User in the neo4j graph
  2. One node containing location information associated with the above node.
Coding Elements
  • 1,000
  • 10
  • 14

0 Answers0