apoc.schema.properties.distinctCount

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

  • Prior to the release of APOC 2025.07, this procedure was restricted on on-premise instances. To use it on an older version, it must be unrestricted. For more details, see Installation → Load and unrestrict.

Details

Syntax

apoc.schema.properties.distinctCount([ label, key ]) :: (label, key, value, count)

Description

Returns all distinct property values and counts for the given key.

Input arguments

Name

Type

Description

label

STRING

The node label to count distinct properties on. If set to , the distinct property values for all labels will be found. The default is: .

key

STRING

The name of the property to count distinct values of. If set to , the distinct property values for the specified label and all property names will be found. The default is: .

Return arguments

Name

Type

Description

label

STRING

The label of the node.

key

STRING

The name of the property key.

value

ANY

The distinct value.

count

INTEGER

The number of occurrences of the value.

Usage Examples

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

CREATE (:Person {name: "Michael", age: 45});
CREATE (:Person {name: "Ryan", age: 33});
CREATE (:Person {name: "Michael", age: 42});
CREATE (:Dog {name: "Shadow", age: 11});

Specific label and property name

CALL apoc.schema.properties.distinctCount("Person", "name");
Results
label key value count

"Person"

"name"

"Michael"

2

"Person"

"name"

"Ryan"

1

All labels and specific property name

Setting the input argument label to `` will return the distinct property values and counts for all labels and the specified property name.

CALL apoc.schema.properties.distinctCount("", "name");
Results
label key value count

"Person"

"name"

"Michael"

2

"Person"

"name"

"Ryan"

1

"Dog"

"name"

"Shadow"

1

Specific label and all property names

Setting the input argument key to `` will return the distinct property values and counts for the specified label and all property names.

CALL apoc.schema.properties.distinctCount("Person", "");
Results
label key value count

"Person"

"name"

"Michael"

2

"Person"

"name"

"Ryan"

1

"Person"

"age"

45

1

"Person"

"age"

33

1

"Person"

"age"

42

1

All labels and all property names

Setting the input arguments label and key to `` will return the distinct property values and counts for the all labels and property names.

CALL apoc.schema.properties.distinctCount("", "");
Results
label key value count

"Person"

"name"

"Michael"

2

"Person"

"name"

"Ryan"

1

"Dog"

"name"

"Shadow"

1

"Person"

"age"

45

1

"Person"

"age"

33

1

"Person"

"age"

42

1

"Dog"

"age"

11

1

In APOC 2025.11, this procedure went through a bigger refactoring including several bug fixes. As a result the behavior has changed compared to previous versions in multiple cases:

Changed behavior
Index on the label and key combination Property values Behavior before 2025.11 Behavior from 2025.11

No index

-

Without any index, the procedure would return an empty result.

The procedure will return the same result with and without an index, but might be slower without an index.

Multiple types of indexes

-

Could lead to an error depending on in which order the indexes were created

Will never cause an error

A non-range index

Mixed property types

Only property values of the same type as the index would be included in the result.

All property values will be included in the result.

A range index

Identical property values of type LIST

Each list would be considered distinct and get its own result row with count 1.

The lists are considered the same value so they will have a single result row with the total count.

A range index

Property values created in the same transaction

Would not be included in the result

Will be included in the result

One or multiple range indexes

The label or key input arguments set to ``

Only label and property combinations covered by any of the indexes would be included in the result.

All relevant label and property combinations will be included in the result.