Skip to content

Instantly share code, notes, and snippets.

@ernestoe
Created April 17, 2015 16:30
Show Gist options
  • Save ernestoe/c514e9f485451595c403 to your computer and use it in GitHub Desktop.
Save ernestoe/c514e9f485451595c403 to your computer and use it in GitHub Desktop.
Generic introspection script for obtaining information about labels, keys and frequencies
// Generic introspection script for obtaining information about labels, keys and frequencies
// first let's extract all distinct labels and their frequencies
MATCH
(node)
WITH
labels(node) AS labels
UNWIND
labels AS label
WITH
label, count(*) as label_count
MATCH
(node)
WHERE
label IN labels(node)
UNWIND
keys(node) as key
WITH
label, label_count, key, count(*) as key_count
ORDER BY
key_count DESC
WITH
label, label_count, collect(key + ':' + key_count) as key_frequency
// with distinct labels + key frequency let's compute label frequency
MATCH
(node)
WHERE
label in labels(node)
UNWIND
labels(node) as sublabel
WITH
label, label_count, key_frequency, sublabel, count(*) as sublabel_count
ORDER BY
sublabel_count DESC
RETURN
label, label_count, key_frequency, collect(sublabel + ':' + sublabel_count) as label_frequency
ORDER BY
label_count DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment