I need to get a distinct listing of all the properties that have been created on a set of nodes in our graph. Everything I know to do or finding in searches is going to return a listing of all nodes of such label and their individual distinct properties. For example:
CREATE (p:Person { name: 'John', age: 40, address: '100 main st' });
CREATE (a:Animal { name: 'Spot', type: 'dog', age: 2, diet: 'dry food'});
CREATE (a:Animal { name: 'Goldie', type: 'fish', family: 'carp' });
I want to get a distinct list back that just returns all the property keys for all Animals.
[ name, type, age, diet, family ]
doing something like this:
MATCH (a:Animal) RETURN distinct keys(a);
returns a list for each node:
[name, type, age, diet]
[name, type, family]
I just want a list of existing property keys for all of one label type. It also needs to be able to scale to millions of nodes.
Just have to unwind the key collections and recombine them.
MATCH (a:Animal)
UNWIND keys(a) AS key
RETURN collect(distinct key)
Alternatively, if you wanted them sorted alphabetically you could do something like this
MATCH (a:Animal)
UNWIND keys(a) AS key
WITH DISTINCT key
ORDER by key
RETURN collect(key)
Or you could return the count of each key
MATCH (a:Animal)
UNWIND keys(a) AS key
RETURN key, count(*) AS num
ORDER by num DESC, key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With