Reputation: 760
I am trying to come up with the Cypher syntax to both:
Since labels cannot be used for relationships, how could it be done?
Upvotes: 1
Views: 1223
Reputation: 1997
Unfortunately, you can't add index to relationships in Neo4j. So, you ca't query database for specific relationship by it's property value.
There are alternatives.
You can reorganize data in such way that:
Usually you can design that in a way when properties that are needed for queries are in nodes, and only additional properties (i.e. cost
) are in relationship.
Anyway you can query relationship by specific property:
MATCH (start)-[:RELATIONSHIP {property: "value"}]->(end)
This will end up in fullscan of :RELATIONSHIP
scope.
If you know id's for start and end nodes, and want to update property for specific relationship, then this one should work:
MATCH (start)-[r:RELTYPE {property: "value"}]->(end)
WHERE id(start) = 1 AND id(end) = 2
WITH r
SET r.property = "new_value"
RETURN r
Warning: this functionality is deprecated. I believe that it will be removed in Neo4j 3.0.0.
But there is - Relationship indexes. You can checkout what it provides and if this functionality can be used in your app.
Upvotes: 1