26
votes

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?

8

8 Answers

15
votes

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

13
votes

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
3
votes

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 .

1
votes

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)

1
votes

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

1
votes

If you delete the index of that labels, then it will delete the labels from database.

0
votes

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.

0
votes

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