I'm using Neo4j Enterprise Edition. I want to clear the whole database I have created before . I mean Every single Node and it's relationships and also properties So I found this syntax on Neo4j book I ran the syntax :
MATCH (a)
OPTIONAL MATCH (a)-[r]-()
DELETE a, r
But still can see the properties on the property keys part
what's wrong?
What should I do so that even properties get deleted?
Neo4j Browser just show the data returned from CALL db.propertyKeys(). Currently the procedure db.propertyKeys() is returning unused properties, as you can see in this GitHub issue at Neo4j Repo.
That is: your database is totally empty, but Neo4j Browser still showing the properties that existed in your database at some point of time.
Since you are deleting all your nodes and relationships, you can alternatively delete all content of <neo4j-home>/data/databases/graph.db/ folder and restart Neo4j service. But you will need to recreate all indexes, constraints and do authentication again.
Tip: Currently you can use DETACH DELETE to delete a node and any relationship going to or from it. So instead of the query yo wrote you can use:
match (node)
detach delete node
Related
I deleted all of node and relationship. Now, I want to delete all existing labels with a Cypher query but I can't.
You are probably referring to the neo4j browser's "Node labels" display. The browser can continue to display labels that have been deleted from all nodes (or even if the DB no longer has any nodes). This is really just a minor nuisance.
As long as your Cypher queries show that there are no nodes with that label, rest assured that the label does not "really" exist in the DB.
If you're removing all of the data (nodes and relationships) anyway, you might as well delete your graph.db directory or wherever you store your data. This will also result in having pre-existing labels not show up in the browser.
This will also remove all indexes you might have had set up.
I have a script that runs in the background and "fix" nodes, which means it does a lot of removing and creating relationships.
While this script is running, I try to run the following Cypher query:
MATCH (pr:Property)-[r2:SIMILAR*0..1]-()<-[r]-(it:Item)
WHERE pr.name in ["BLACK","BLACK2"] and toFloat(it.crawler) >= 3.8
return pr.name, type(r),it
I run it a few times. Sometimes I get an answer and sometimes I get something like:
Unable to load RELATIONSHIP with id 9765815.
Neo.ClientError.Statement.EntityNotFound
Of course the 'id' changes all the time.
I understand that in the middle of computation, some of the relationships change. But I thought neo4j knows how to handle it and return the last "true" results (CRUD).
Is there a way to ignore the changes and return the current results?
I'm running neo4j-enterprise 2.0.3.
EDIT :
I'm running the query both from the browser and from the nodejs neo4j agent
Neo4j is fully ACID, the "I" meaning isolation, i.e. transactions should not see each other's uncommitted modifications. Therefore, you're right in saying that Neo4j should handle it.
Here's what I think is happening. The Cypher query, since it executes in a single transaction, always succeeds, no problem there. But something happens afterwards: the "browser" that ships with Neo4j always displays all relationships between nodes that it is displaying, no matter if you asked for them or not. I'm assuming that loading these is part of a different transaction than your original Cypher query. In that case, it can encounter relationships that it thinks exist, but have been deleted in the meantime by your script.
This is an assumption, but should be easy to verify. If it's correct, then:
if you change it (the whole node) to it.someProperty, then the issue should never occur
if you run the original cypher query from (let's say) the command line or via REST, but not from the browser, the issue should never occur
Please let us know your findings. Cheers
How to delete labels in neo4j? Actually I deleted all nodes and relationships, then I recreated the movie database and still the labels I created before appeared on the webinterface. I also tried to use a different location for the database and even after an uninstall and reinstall the labels still appeared. Why? Where are the labels stored? After the uninstall the programm, the database folder and the appdata folder were deleted.
How to reproduce? Install neo4j -> use the movie database example -> create (l:SomeLabel {name:"A freaky label"}) -> delete the node -> stop neo, create new folder -> start neo -> create movie shema -> match (n) return (n) -> SomeLabel appears, even if you changed the folder or make an uninstall / install.
Is there a way to delete labels even if there is no node with it?
There isn't at the moment (Neo4j 2.0.1) a way to explicitly delete a label once it has been created. Neo4j Browser will display all labels which are reported by the REST endpoint at:
http://localhost:7474/db/data/labels
Separately, the Neo4j Browser sidebar which displays labels doesn't properly refresh the listing when it loses connection with Neo4j. A web browser reload should work.
Lastly, there was a bug in Neo4j Browser's visualization which would display all labels for which a style had been created. If using a version of Neo4j which has the bug, you can clear the styling by clicking on "View Stylesheet" in the property inspector, then clicking the fire extinguisher icon. All of that needs usability improvement, admittedly.
Cheers,
Andreas
This seems to be worked out by version 2.3.0.
As an example, suppose we had created a movie in the data browser such as:
CREATE(m:Movie:Cinema:Film:Picture{title:"The Matrix"})
We could query it with
MATCH(m:Movie)
WHERE m.title = "The Matrix"
RETURN m
It would have 4 labels: Movie, Cinema, Film, and Picture
To remove the Picture label from all movies:
MATCH(m:Movie)
REMOVE m:Picture
RETURN m
To remove the Picture label from only that one movie:
MATCH(m:Movie)
WHERE m.title = "The Matrix"
REMOVE m:Picture
RETURN m
Let us assume that we have created a node Product as below
PRODUCT_MASTER { product_code :"ABC", product_name:"XYX }
CREATE INDEX ON :PRODUCT_MASTER (product_code);
Now even if I delete all PRODUCT_MASTER nodes from graph, we will keep getting PRODUCT_MASTER in browser under Node labels. To get rid of the same , we need to drop the index as well.
DROP INDEX ON :PRODUCT_MASTER (product_code);
In neo4j-shell , type in "schema" command to get the list of indexes and corresponding properties.
To summarize , in case we delete all of the nodes of particular type , you need delete indexes on that node as well .
I simply:
stop neo4j
delete the entire database, and that removes everything
start neo4j
on a mac the db is here
/usr/local/var/neo4j/data/databases/graph.db
The reason is that when a label is created, Neo4j indexes this label. You can delete the node but the index will remain.
At a guess - if you drop the index on the label, it will disappear from the GUI (NOTE- I've not got access to Neo4j at the moment to check this theory)
If you delete the index of that labels, then it will delete the labels from database.
I just found a workaround (with neo4j 2.2 M04). Dump the content of the DB to a file, throw away the DB, then insert the dump again. Only works for small DBs, though.
Step1: dump the content, using neo4j-shell
$NEO4J_HOME/bin/> neo4j-shell -c 'dump match a return a;' > dump.temp
Step2: throw away DB
(there's plenty ways to delete the folder $NEO4J_HOME/data/graph.db/ or wherever your DB folder is)
Step3: insert the dump again, using neo4j-shell
$NEO4J_HOME/bin/> neo4j-shell -file dump.temp
This should bring up statistics on how many nodes, relationships, properties and labels have been created.
(And Step4 would be to delete that dump.temp file, it has no reason to live inside the bin folder.)
What I find odd (and maybe Michael or somebody else from neo4j could shed some light on this): in my case, Step3 told me that some 50+ labels had been created. However, when I open the web interface, only those 15 or so labels, which I actually use, are listed. So the DB feels clean now. Not entirely sure that it is clean.
As of today, with Neo4j Desktop Version: 1.1.10 and DB Version: 3.4.7
Delete data + delete Index + delete any unique constraints + Developer > Refresh clears all Labels
I want to create a new Database in neo4j using Cypher as I am not a Java (or Programming language) guy but a Database person ....Could I create a neo4j database using Cypher before creating nodes and relationships ...I am using ne04j community console and would like to create a new database
Thanks !
There is only one database.
You can clean out your current data by either stopping the server and removing the database on disk /path/to/neo4j/data/graph.db and starting it again.
Or by executing a Cypher statement like:
MATCH (n)
OPTIONAL MATCH (n)-[r]->()
DELETE n,r
You dont need to create a new database as(neo4j folder)\data\graph.db is the default path for the database.Neo4j is different from the relational databases.Folder it self is a database.In a graph database you have to create three things: nodes,relationships and properties.
If you want to change the database path you can change the path in conf/neo4j-server.properties.
You can also refer below link:
How to delete/create databases in Neo4j?
I deleted the reference node. So I need to recreate the reference node.
Using cypher how to create a node with id 0?
thanks.
The short answer is you can't, and you don't need to. Do you have a specific problem without that node? If so, maybe you can elaborate, chances are there is something else that answers your problem better than trying to recreate a node with a specific id.
The long answer is you can't assign id:s to nodes with cypher. The id is an index or offset into the node storage on disk, so it makes sense to let Neo4j worry about it and not try to manipulate it or include it in any application logic. See Node identifiers in neo4j and Has anyone used Neo4j node IDs as foreign keys to other databases for large property sets?.
You also most likely don't need a reference node. It is created by default in a new database, but it's use is deprecated and it won't exist in future releases. See Is concept of reference node in neo4j still used or deprecated?.
If you still want to assign id to nodes you create, it is accidentally possible in a roundabout way with with the CSV batch importer (1,2) and, I believe, with the Java API batch inserter.
If you still want to recreate or simulate the reference node you can either delete the database data files and let Neo4j recreate the the database, or you can try what this person did: Recreate reference node in a Neo4j database. You can also force Neo4j to recycle the ids of deleted nodes faster, so that new nodes that you create receive those ids that have been freed up and not yet reassigned.