Get node by property value neo4j

user3688491 picture user3688491 · Apr 1, 2015 · Viewed 11.1k times · Source

How can i get node by propery value? I mean something like that: I'll tried

match (n) where has (n.name = 'Mark') return n

But it's incorrect.

And also How can i find node with max property value. I have nodes with property "VIEWS" and i want see node with max views.

Answer

Dave Bennett picture Dave Bennett · Apr 1, 2015

So close...

MATCH (n) 
WHERE n.name = 'Mark' 
RETURN n

It is better to include a node label if you have one that will serve to segregate your node from other nodes of different types. This way if you have an index on the name property and label combination you will get better search responsiveness. For instance, you can create the index...

CREATE INDEX ON :Person(name)

And then query with the Person label.

MATCH (n:Person) 
WHERE n.name = 'Mark' 
RETURN n

Or alternatively you can query this way...

MATCH (n:Person {name:'Mark'}) 
RETURN n

To find the person with the most views...

MATCH (n:Person)
RETURN n, n.views
ORDER BY n.views desc
LIMIT 1

To find the most views without the person...

MATCH (n:Person)
RETURN max(n.views)