Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get node by property value neo4j

Tags:

neo4j

cypher

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.

like image 477
user3688491 Avatar asked Apr 01 '15 02:04

user3688491


1 Answers

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)
like image 173
Dave Bennett Avatar answered Oct 18 '22 17:10

Dave Bennett