Property value to a label

The APOC library contains a procedure that can be used to create a label from a property value.

Procedure for creating a label from a property value

Qualified Name Type

apoc.create.addLabels(nodes ANY, label LIST<STRING>) - adds the given labels to the given NODE values.

Procedure

Example

The below example will further explain this procedure.

The following creates a Movie node with title and genre properties
CREATE (:Movie {title: 'A Few Good Men', genre: 'Drama'})
The following moves the 'genre' property to a label and removes it as a property
MATCH (n:Movie)
CALL apoc.create.addLabels( id(n), [ n.genre ] )
YIELD node
REMOVE node.genre
RETURN node