user2565192
user2565192

Reputation: 654

return nodes with selected properties

I am using a graph database having many nodes connected to a super node by a relationship TYPE. And each of those sub nodes have properties via a FROM relationship. How should i access the properties of individual nodes in cypher query?

I tried this but its not working.

start a=node(2) match (a)<-[:TYPE]-(node) match (node)<-[:FROM]-(prop) where prop.name="ABC" return node;

Here i have to return a node with a property name whose value is ABC!? How should i correct it?

Upvotes: 1

Views: 561

Answers (1)

Andrew Lank
Andrew Lank

Reputation: 1617

START a=node(2) 
MATCH (a)<-[:TYPE]-(node)<-[:FROM]-(prop)
WHERE prop.name="ABC" 
RETURN node;

You could also do this using indexes:

START a=node:properties('name:ABC')
MATCH (node)<-[:FROM]-(a)

Where 'properties' is your index which indexes name as 'ABC'. Realize that your above query is only interested in the node related with :FROM, therefore searching in the first example could be very long compared to simply using indexing.

If you are using Neo4j 2.x, then you are far better off with labels.

MATCH (a:Property(name='ABC'))-[:FROM]->(node)
RETURN node

Where you would set the label 'Property' when you create/update a property node.

Upvotes: 3

Related Questions