How to get a list of node properties with Cypher in Neo4j?
Asked Answered
M

8

15

I'm trying to list all of the properties for a set of nodes.

Match (n:"Indicator")
return properties(n), ID(n) 

I'm unsure of the syntax and couldn't find the answer in the refcard or docs.

Mage answered 14/4, 2014 at 17:53 Comment(2)
You can [do this with java][1], but you can't do it in Cypher, AFAIK. [1]: #17413284Susysuter
interesting tidbits about this topic can be found in this abstract request docs.google.com/document/d/…Postdate
H
14

In Neo4j version 3.0.0 you may do:

Match (n:Indicator) return properties(n), ID(n) 

To return the ID and properties of nodes.

Hardie answered 3/6, 2016 at 5:19 Comment(0)
M
5

At the moment you can't do this using cypher but it is on the top five on the ideas board.

Manor answered 1/5, 2014 at 13:25 Comment(0)
T
4
MATCH (n)
RETURN DISTINCT keys(n), size(keys(n))
ORDER BY size(keys(n)) DESC 
Tabaret answered 30/8, 2018 at 16:58 Comment(0)
G
2

Properties(n) works if you need the properties of the node with the key and value, but if you only need to see the properties name's in a easy way you can do this. Example:

MATCH (n:Indicator) return ID(n), keys(n), size(keys(n))

Results: Results from Neo4j browser Results from Neo4j browser

You can quit ID(n) and size(keys(n)) without problem but is good if you need to identify a node that dont have the required properties or is not complete.

Also you can use a DISTINCT if you have generic and repetitive properties on the same type of Node like this.

MATCH (n:Indicator) return DISTINCT ID(n), keys(n), size(keys(n))

As I have said this also works without problems and give you the array of properties that you need.

MATCH (n:Indicator) return keys(n)

Result only returning keys Result only returning keys

But you can resume this long list of results, with a DISTINCT

MATCH (n:Indicator) return DISTINCT keys(n)

Result with only the differents lists of properties that the Node (n) have Result with only the differents lists of properties that the Node (n) have

Guerra answered 17/4, 2019 at 15:52 Comment(1)
Underrated answer.Lajoie
C
2
MATCH (n:Label)
WITH DISTINCT(keys(n)) as key_sets
UNWIND(key_sets) as keys
RETURN DISTINCT(keys) as key

This will return a clean list of distinct keys

Correlation answered 25/1, 2023 at 20:34 Comment(0)
S
1

If you have APOC installed, I use this to get a distinct list of all node property combinations:

MATCH (n) 
RETURN DISTINCT apoc.coll.sort(keys(n)) as props
               ,size(keys(n)) as key_size

Note: you don't have to use APOC, but if you don't you'll get duplicates where values are same, but ordering is different, so sorting combines them

Sopor answered 12/8, 2020 at 20:44 Comment(0)
T
1

I know this post is old, but when I had a similar question, I found the command below to be the solution that returned all the information I needed, which was to list out the properties for each node in the database, and include the property type(s) of each value for each node:

CALL db.schema.nodeTypeProperties()

Additionally, you can do the same thing for relationships:

CALL db.schema.relTypeProperties()

The nice part is that this will work with cypher shell and does not require APOC to be installed.

Trubow answered 7/7, 2023 at 18:32 Comment(0)
E
0

in the case where the keys are returned in different orders, this does the trick:

MATCH (n)
UNWIND keys(n) AS allProps
RETURN COLLECT(DISTINCT allProps) as distinctProps
Expansible answered 6/12, 2022 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.