Collect all unique properties values from my graph using CYPHER

Hi !

Firstable I would like to say that I am a beginner in CYPHER queries and KG management.
I try to find clues on previous topic unsuccesfully, but if I miss something i am sorry.

Secondly : neo4j 5.10.0, Desktp : 1.5.8, Browser 5.12.0

My Goal :
I would like to make a CYPHER query for getting all my properties values.

Labels | Properties | Values
Actor | birth_date | [1957, 1972, ...]
Actor | name | [Bruce Willis, Natalie Portman,...]
Film | name | [...]
...

I succeed to find some but I am not able to aggregate the results for getting my answer.

I am able to :

  • Find all the properties as a list
Match(n)
WITH labels(n) as list_lab_in, keys(n) as Keys
UNWIND  Keys as key
WITH DISTINCT collect(key) as list_key
RETURN list_key
  • Find a table which is close to my need with the query :
MATCH (n)
WITH n, keys(n) as props
UNWIND props as key
UNWIND labels(n) as Labels
return DISTINCT Labels, Properties, n[key] as Value

Output :
Labels | Properties | Value
"Label1"| "Property_1" | "Value"
"Label1"| "Property_2" | "Value"
...

I don't succeed to use a comprehension list for iterate over my list_key for get all the values of this properties.
Do I am close to get it ?
Do anyone have clue to provide ? Any doc, I try APOC doc, CYPHER, but I dont find there.

Kindly,
Max

match (n)
with labels(n) as labels, keys(n) as properties, n
unwind properties as property
return labels, property, n[property] as value limit 10

Be ware, this is going to be a long list :)

Hi Hakan,

Firstable thank you about consider my request.

Is it possible to wrap/aggregate all the values under a list ?

I can use this table and get the results i want using python, but I want to improve this query.

The table I get with your answer is very long as you mentionned, the length could be something like count(keys), what i want is a table with a length of count(DISTINCT Keys), with list of all the values possible for the key in the VALUES column.

best regards

Try this slight modification to @hakan.lofqvist1’s solution:

match (n)
with labels(n) as labels, keys(n) as properties, n
unwind properties as property
return labels, property, collect(distinct n[property]) as value
limit 10

If you know every node has a single label, you can safely remove the label list in your result:

match (n)
with head(labels(n)) as label, keys(n) as properties, n
unwind properties as property
return label, property, collect(distinct n[property]) as value
limit 10

As a note, null values are ignored in the collect function. If you have some properties with null values, the query can be modified to show this.

You can also do something like this:

match (n)
return head(labels(n)) as label, n{.*} as properties
limit 10