Reputation: 871
I have created a graph database using py2neo and the purpose is:
I created city nodes first (successfully) using this module:
batch = neo4j.WriteBatch(graph_db)
for city_id,city_name in <some_list>:
city_node_id = batch.create(node(city_id=city_id, name=city_name))
batch.add_indexed_node('city_index','city_id',city_id, city_node_id)
batch.submit()
Then in another separate module I tried to create airport nodes and relationship between the airport node and corresponding city node like this:
read_batch = neo4j.ReadBatch(graph_db)
write_batch = neo4j.WriteBatch(graph_db)
for airport_id, city_id, airport_name in <some_list>:
airport_node_id = write_batch.create(node(airport_id=airport_id, city_id=city_id, name=airport_name))
write_batch.add_indexed_node('airport_index','airport_id',airport_id, airport_node_id)
city_node_id = read_batch.get_indexed_nodes('city_index','city_id',city_id)
rel_id = write_batch.create(rel(airport_node_id, "is in city", city_node_id))
write_batch.add_indexed_relationship('airport_rel_index','airport_id',airport_id, rel_id)
write_batch.submit()
The 3rd statement from last wherein I am creating relationships is throwing exception:
rel_id = write_batch.create(rel(airport_node_id, "is in city", city_node_id))
File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 2695, in create
"to": self._uri_for(entity.end_node)
File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 2537, in _uri_for
uri = "{{{0}}}".format(self.find(resource))
File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 2528, in find
raise ValueError("Request not found")
ValueError: Request not found
I tried to print uri of both the types of nodes. Their is a difference:
print station_node_id._uri, city_node_id._uri
Output:
node index/node/city_index/city_id/2536650
So the uris of both nodes are different, which is why I guess the relationship is not getting created.
What function can I use which returns the unindexed node for city i.e. uri should be just "node" instead of the "index/node/city_index/city_id/".
Is there any other way to create this relationship?
I would be happy to provide any other information if need be. Thanks in advance!
Neo4j: 1.9.5
py2neo: 1.6.1
Upvotes: 1
Views: 325
Reputation: 4495
What you're seeing is an unfortunate server limitation whereby the Location URIs returned by some REST calls contain a node index entry URI instead of a standard node URI. This is unfortunately useful only in a few use cases and a major limitation in cases like yours.
There is a similar issue discussed here - https://github.com/nigelsmall/py2neo/issues/221 - and unfortunately nothing I can do from the client side.
Your only real option is to split your work into multiple batches or - if you are able to do so - consider an upgrade to Neo4j 2.0 where you can use the new label and schema index capabilities.
Upvotes: 1