How do I find disconnected nodes on neo4j with Cypher?
-
09-04-2021 - |
質問
I am toying with neo4j and noticed that all Cypher queries need a starting point in the START
clause.
I was wondering how can I find all disconnected nodes using Cypher ?
thanks
解決
If all your nodes are indexed (e.g. via auto-indexing) you could use an index query as a start point and then find those nodes that have no outgoing relationships.
start n=node:node_auto_index("id:*")
match n-[r?]->m
where r is null
return n
Nowadays I would rather use:
start n=node:node_auto_index("id:*")
where not (n-->m)
return n
他のヒント
I use something like this, but only when I'm using spring-data-neo4j:
start n = node:__types__(className="com.app.entity.Model")
// match, where...
return n
Hope that helps!
With Neo4j v3.0+ I just use;
MATCH (n)
WHERE NOT (n)--()
RETURN n
(or variations thereof). The query is reasonably fast.
You can't. Graph global queries are not possible with todays Cypher.
所属していません StackOverflow