Neo4j – Is there a cypher query syntax to list (show) all indexes in DB?
neo4j 3.1 now supports this as a built-in procedure that you can CALL from Cypher: CALL db.indexes(); http://neo4j.com/docs/operations-manual/3.1/reference/procedures/
neo4j 3.1 now supports this as a built-in procedure that you can CALL from Cypher: CALL db.indexes(); http://neo4j.com/docs/operations-manual/3.1/reference/procedures/
In Neo4j 2.0 you can create schema indexes for your labels and the properties you use for lookup: CREATE INDEX ON :User(username) CREATE INDEX ON :Role(name) To create relationships you might use: MATCH (u:User {username:’admin’}), (r:Role {name:’ROLE_WEB_USER’}) CREATE (u)-[:HAS_ROLE]->(r) The MATCH will use an index if possible. If there is no index, it will lookup … Read more
So, this gives you all nodes: MATCH (n) RETURN n; If you want to delete everything from a graph, you can do something like this: MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r; Updated for 2.0+ Edit: Now in 2.3 they have DETACH DELETE, so you can do something like: MATCH (n) DETACH DELETE n;
That’s in the reference docs, see http://docs.neo4j.org/chunked/stable/query-set.html#set-set-a-label-on-a-node, you need to use set to a add a label to a existing node: match (n {id:desired-id}) set n :newLabel return n
You can put this condition in the WHERE clause: MATCH (n) WHERE n:Male OR n:Female RETURN n EDIT As @tbaum points out this performs an AllNodesScan. I wrote the answer when labels were fairly new and expected the query planner to eventually implement it with a NodeByLabelScan for each label, as it does for the … Read more
using regular expressions: http://neo4j.com/docs/developer-manual/current/#query-where-regex start n = node(*) where n.Name =~ ‘.*SUBSTRING.*’ return n.Name, n;
To get all distinct node labels: MATCH (n) RETURN distinct labels(n) To get the node count for each label: MATCH (n) RETURN distinct labels(n), count(*)
Update 01/10/2013: Came across this in the Neo4j 2.0 reference: Try not to use optional relationships. Above all, don’t use them like this: MATCH a-[r?:LOVES]->() WHERE r IS NULL where you just make sure that they don’t exist. Instead do this like so: MATCH a WHERE NOT (a)-[:LOVES]->() Using cypher for checking if relationship doesn’t … Read more
Shut down your Neo4j server, do a rm -rf data/graph.db and start up the server again. This procedure completely wipes your data, so handle with care.
For general querying, Cypher is enough and is probably faster. The advantage of Gremlin over Cypher is when you get into high level traversing. In Gremlin, you can better define the exact traversal pattern (or your own algorithms) whereas in Cypher the engine tries to find the best traversing solution itself. I personally use Cypher … Read more