26

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?

Matthias Baumgart
  • 905
  • 1
  • 9
  • 22

8 Answers8

15

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

akollegger
  • 1,124
  • 10
  • 13
  • Good to know. REST returns only the labels from the movie database, and even in the neo4j browser sidebar onlye the movie database labels appear. But what I really meant by the question is the neo4j broser visualization: When I ask for `MATCH (n) RETURN n` then all the old labels appear even after uninstall/reinstall/browser refresh. That is really weird. – Matthias Baumgart Feb 25 '14 at 07:23
  • Updated my response to include mention of a bug in the browser visualization. There are some outstanding UI/UX quirks which will get fixed. – akollegger Feb 26 '14 at 17:27
  • 2
    In Neo4j 3.0.1, all I needed to do is remove the label from all nodes, and then remove any index on the label. As soon as I removed the index, the label was gone from the sidebar. `DROP INDEX ON :Label(property)` – ADTC May 12 '16 at 20:50
  • @ADTC can you share a bigger example on this because I cannot seem to do this in 4.4* browser version. – p0lAris Dec 30 '21 at 01:44
  • @p0lAris sorry, this is an old comment. I don't have the resources to do so. – ADTC Feb 21 '22 at 09:41
13

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
ThisClark
  • 14,352
  • 10
  • 69
  • 100
  • 1
    How to remove all labels in a single shot? – Jack Daniel Sep 08 '16 at 06:29
  • @JackDaniel I haven't used Neo4j in a while. It's probably best you open your question as a new question here on StackOverflow. You can link to this answer as an effort to show your research so far. – ThisClark Sep 08 '16 at 14:15
3

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 .

Steve Tjoa
  • 59,122
  • 18
  • 90
  • 101
Gyro
  • 733
  • 7
  • 11
2

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

user2228895
  • 167
  • 7
1

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)

joe
  • 1,851
  • 3
  • 17
  • 29
1

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

0

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.

rene
  • 101
  • 2
  • 7
0

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

Namrata
  • 59
  • 5