apoc.schema.nodes

This procedure is not considered safe to run from multiple threads. It is therefore not supported by the parallel runtime (introduced in Neo4j 5.13). For more information, see the Cypher Manual → Parallel runtime.

Details

Syntax

apoc.schema.nodes([ config ]) :: (name, label, properties, status, type, failure, populationProgress, size, valuesSelectivity, userDescription)

Description

Returns all indexes and constraints information for all NODE labels in the database. It is possible to define a set of labels to include or exclude in the config parameters.

Input arguments

Name

Type

Description

config

MAP

{ labels :: LIST<STRING>, excludeLabels :: LIST<STRING>, relationships :: LIST<STRING>, excludeRelationships :: LIST<STRING> }. The default is: {}.

Return arguments

Name

Type

Description

name

STRING

A generated name for the index or constraint.

label

ANY

The label associated with the constraint or index.

properties

LIST<STRING>

The property keys associated with the constraint or index.

status

STRING

The status of the constraint or index.

type

STRING

The type of the index or constraint.

failure

STRING

If a failure has occurred.

populationProgress

FLOAT

The percentage of the constraint or index population.

size

INTEGER

The number of entries in the given constraint or index.

valuesSelectivity

FLOAT

A ratio between 0.0 and 1.0, representing how many unique values were seen from the sampling.

userDescription

STRING

A descriptor of the constraint or index.

Signature

apoc.schema.nodes(config = {} :: MAP) :: (name :: STRING, label :: ANY, properties :: LIST<STRING>, status :: STRING, type :: STRING, failure :: STRING, populationProgress :: FLOAT, size :: INTEGER, valuesSelectivity :: FLOAT, userDescription :: STRING)

Input parameters

Name Type Default

config

MAP

{}

Config parameters

The procedure supports the following config parameters:

Config parameters
name type default description

labels

LIST<STRING>

[]

list of labels to retrieve index/constraint information. Default is to include all labels.

excludeLabels

LIST<STRING>

[]

list of labels to exclude from retrieve index/constraint information. Default is to include all labels.

It’s not possible to evaluate both labels and excludeLabels. In this case, the error Parameters labels and excludeLabels are both valued. will be thrown.

Output parameters

Name Type

name

STRING

label

ANY

properties

LIST<STRING>

status

STRING

type

STRING

failure

STRING

populationProgress

FLOAT

size

INTEGER

valuesSelectivity

FLOAT

userDescription

STRING

Usage Examples

The type result can have one of the following values:

type output
name Schema type

"UNIQUENESS"

Unique node property constraint

"NODE_PROPERTY_EXISTENCE"

Node property existence constraint

"NODE_KEY"

Node key constraint

"FULLTEXT"

Full-text index

"TEXT"

Text index

"RANGE"

Range index

"POINT"

Point index

"LOOKUP"

Lookup index

Community Edition example

Given the following schema:

CREATE CONSTRAINT personName FOR (person:Person)
REQUIRE person.name IS UNIQUE;

CREATE CONSTRAINT userId FOR (user:User)
REQUIRE user.id IS UNIQUE;

CREATE FULLTEXT INDEX fullIdx FOR (n:Movie|Book) ON EACH [n.title, n.description];

CREATE POINT INDEX pointIdx FOR (n:Place) ON (n.address);

CREATE TEXT INDEX textIdx FOR (n:Game) ON (n.title);

It is possible to execute the following query:

CALL apoc.schema.nodes()
Results
name label properties status type failure populationProgress size valuesSelectivity userDescription

":Person(name)"

"Person"

["name"]

""

"UNIQUENESS"

"NO FAILURE"

0.0

0

0.0

"Constraint( id=8, name='personName', type='UNIQUENESS', schema=(:Person {name}), ownedIndex=7 )"

":User(id)"

"User"

["id"]

""

"UNIQUENESS"

"NO FAILURE"

0.0

0

0.0

"Constraint( id=4, name='userId', type='UNIQUENESS', schema=(:User {id}), ownedIndex=3 )"

":Game(title)"

"Game"

["title"]

"ONLINE"

"TEXT"

"NO FAILURE"

100.0

0

1.0

"Index( id=9, name='textIdx', type='TEXT', schema=(:Game {title}), indexProvider='text-2.0' )"

":Person(name)"

"Person"

["name"]

"ONLINE"

"RANGE"

"NO FAILURE"

100.0

0

1.0

"Index( id=7, name='personName', type='RANGE', schema=(:Person {name}), indexProvider='range-1.0', owningConstraint=8 )"

":Place(address)"

"Place"

["address"]

"ONLINE"

"POINT"

"NO FAILURE"

100.0

0

1.0

"Index( id=6, name='pointIdx', type='POINT', schema=(:Place {address}), indexProvider='point-1.0' )"

":User(id)"

"User"

["id"]

"ONLINE"

"RANGE"

"NO FAILURE"

100.0

0

1.0

"Index( id=3, name='userId', type='RANGE', schema=(:User {id}), indexProvider='range-1.0', owningConstraint=4 )"

Please note that the unique node property constraints (i.e. personName and userId) return two results, one for the constraint itself (the rows with type "UNIQUENESS") and one for the index that is created at the same time as the constraint (with type "RANGE").

Enterprise Edition example

Given the following schema:

CREATE CONSTRAINT node_cons IF NOT EXISTS FOR (bar:Bar) REQUIRE bar.foobar IS NOT NULL

CREATE CONSTRAINT FOR (f:Test) REQUIRE (f.bar,f.foo) IS NODE KEY;

It is possible to execute the following query:

CALL apoc.schema.nodes()
Results
name label properties status type failure populationProgress size valuesSelectivity userDescription

":Bar(foobar)"

"Bar"

["foobar"]

""

"NODE_PROPERTY_EXISTENCE"

"NO FAILURE"

0.0

0

0.0

"Constraint( id=7, name='node_cons', type='NODE PROPERTY EXISTENCE', schema=(:Bar {foobar}) )"

":Test(bar,foo)"

"Test"

["bar", "foo"]

""

"NODE_KEY"

"NO FAILURE"

0.0

0

0.0

"Constraint( id=9, name='constraint_d926cedc', type='NODE KEY', schema=(:Test {bar, foo}), ownedIndex=8 )"

":Test(bar,foo)"

"Test"

["bar", "foo"]

"ONLINE"

"RANGE"

"NO FAILURE"

100.0

0

1.0

"Index( id=8, name='constraint_d926cedc', type='RANGE', schema=(:Test {bar, foo}), indexProvider='range-1.0', owningConstraint=9 )"

Similarly to unique node property constraints, the node key constraints return two results (with types "NODE_KEY" and "RANGE").

Failure example

Given a node with a string property larger than 32kb, i.e. (:LabelTest {prop: <LARGE_STRING_MORE_THAN_32_KB>}), and the following index:

CREATE INDEX FOR (n:LabelTest) ON (n.prop)

It is possible to execute the following query which will show, in the failure column, a failure message similar to the command output of SHOW INDEX YIELD failureMessage:

CALL apoc.schema.nodes()
Results
name label properties status type failure populationProgress size valuesSelectivity userDescription

":LabelTest(prop)"

"LabelTest"

["prop"]

"FAILED"

"RANGE"

"java.lang.IllegalArgumentException: Property value is too large to index, please see index documentation for limitations. Index: Index( id=6, name='index_58741a3d', type='RANGE', schema=(:LabelTest {prop}), indexProvider='range-1.0' ), entity id: 321, property size: 104815, value: [String("2023-06-19T10:14:05.9391146Z apoc.it.core.SchemasEnterpriseFeaturesTest STANDARD_ERROR 2023…​. at org.neo4j.kernel.api.index.IndexValueValidator.throwSizeViolationException …​

0.0

0

1.0

"Index( id=6, name='index_58741a3d', type='RANGE', schema=(:LabelTest {prop}), indexProvider='range-1.0' )"