apoc.refactor.categorize

Procedure APOC Core

apoc.refactor.categorize(sourceKey, type, outgoing, label, targetKey, copiedKeys, batchSize) turn each unique propertyKey into a category node and connect to it

Signature

apoc.refactor.categorize(sourceKey :: STRING?, type :: STRING?, outgoing :: BOOLEAN?, label :: STRING?, targetKey :: STRING?, copiedKeys :: LIST? OF STRING?, batchSize :: INTEGER?) :: VOID

Input parameters

Name Type Default

sourceKey

STRING?

null

type

STRING?

null

outgoing

BOOLEAN?

null

label

STRING?

null

targetKey

STRING?

null

copiedKeys

LIST? OF STRING?

null

batchSize

INTEGER?

null

Usage Examples

The examples in this section are based on the following sample graph:

CREATE (:Movie {title: 'A Few Good Men', genre: 'Drama'});

We want to move the genre from the Movie node to a new node with the Genre label and name property. We’ll also create a GENRE relationship from the Movie node to that genre node.

This procedure requires us to create a unique constraint on the Genre label, name property, otherwise we’ll get the following exception:

CALL apoc.refactor.categorize('genre', 'GENRE', true, "Genre", "name", [], 100);
Results
Failed to invoke procedure `apoc.refactor.categorize`: Caused by: java.lang.IllegalArgumentException: Before execute this procedure you must define an unique constraint for the label and the targetKey:
CREATE CONSTRAINT ON (n:`Genre`) ASSERT n.`name` IS UNIQUE

Once we’ve created the constraint, we can re-run the procedure, and then see the new graph structure by running the following query:

MATCH p=()-[:GENRE]->()
RETURN p;
apoc.refactor.categorize.usage
Figure 1. New graph structure