Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active June 25, 2020 14:42
Show Gist options
  • Save vladbatushkov/8a9f0897ffa9a8864b7c31dd0bf23b40 to your computer and use it in GitHub Desktop.
Save vladbatushkov/8a9f0897ffa9a8864b7c31dd0bf23b40 to your computer and use it in GitHub Desktop.
Start explore your Neo4j graph with next queries.

Database Schema

CALL db.schema.visualization();

Graph Size

CALL apoc.meta.stats();

Node Label Frequency

CALL db.labels() YIELD label
CALL apoc.cypher.run('MATCH (:`'+label+'`) RETURN count(*) as freq',{})
YIELD value
WITH label,value.freq AS freq
CALL apoc.meta.stats() YIELD nodeCount
WITH *,3 AS presicion
WITH *,10^presicion AS factor,toFloat(freq)/toFloat(nodeCount) AS relFreq
RETURN label AS nodeLabel, freq AS frequency,round(relFreq*factor)/factor AS relativeFrequency
ORDER BY freq DESC;

Relationship Type Frequency

CALL db.relationshipTypes() YIELD relationshipType as type
CALL apoc.cypher.run('MATCH ()-[:`'+type+'`]->() RETURN count(*) as freq',{})
YIELD value
WITH type AS relationshipType, value.freq AS freq
CALL apoc.meta.stats() YIELD relCount
WITH *,3 AS presicion
WITH *, 10^presicion AS factor,toFloat(freq)/toFloat(relCount) as relFreq
RETURN relationshipType, freq AS frequency,
    round(relFreq*factor)/factor AS relativeFrequency
ORDER BY freq DESC;

Nodes & Relationship Properties

CALL apoc.meta.data() YIELD label,property,type,elementType
WHERE type<>'RELATIONSHIP'
RETURN elementType,label,property,type
ORDER BY elementType,label,property;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment