Summary of Node and Relationship Properties

Had a requirement to summarizes unique properties and thought others might find these queries useful:

MATCH (n)
with DISTINCT labels(n) as nd,apoc.coll.sort(keys(n)) as props
with nd,apoc.coll.dropDuplicateNeighbors(apoc.coll.sort(apoc.coll.flatten(collect(props)))) as pr
return nd as nodes,size(pr) as property_ct, pr as properties order by nodes

MATCH ()-[r]-()
with DISTINCT type(r) as rel,apoc.coll.sort(keys(r)) as props
with rel,apoc.coll.dropDuplicateNeighbors(apoc.coll.sort(apoc.coll.flatten(collect(props)))) as pr
return rel,size(pr) as property_ct, pr as properties order by rel

MATCH (n)
with DISTINCT labels(n) as nd,apoc.coll.sort(keys(n)) as props
with nd,apoc.coll.dropDuplicateNeighbors(apoc.coll.sort(apoc.coll.flatten(collect(props)))) as pr
with nd,pr unwind pr as property
return nd as nodes,property order by nodes,property

MATCH ()-[r]-()
with DISTINCT type(r) as rel,apoc.coll.sort(keys(r)) as props
with rel,apoc.coll.dropDuplicateNeighbors(apoc.coll.sort(apoc.coll.flatten(collect(props)))) as pr
with rel,pr unwind pr as property
return rel as relationships,property order by relationships,property

These are also useful;

CALL apoc.meta.nodeTypeProperties()

CALL apoc.meta.relTypeProperties()

1 Like