cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to find all the properties in a label/Node and data type of all the properties

Kailash
Graph Buddy

Team, is there any way to get all the property in a node/Label and data type of all of those?

I am trying below query, but apoc.meta.type(property) gives as STRING Always for all property

call apoc.meta.data() yield label, property
with ['company'] as labels, property, label where label in labels
return property, label , apoc.meta.type(property)

1 ACCEPTED SOLUTION

paulare
Graph Buddy

Hi, @Kailash

Are looking for something like:

MATCH (p:Person {name: 'Eve'})
WITH p
RETURN apoc.meta.cypher.types(p)

{
  "name": "STRING",
  "gender": "STRING",
  "age": "INTEGER",
  "kids": "INTEGER"
}

To get same result, each line separate:

MATCH (p)
WITH distinct p, keys(p) as pKeys
UNWIND pKeys as Key
RETURN distinct labels(p), Key, apoc.map.get(apoc.meta.cypher.types(p), Key, [true])

Result

╒═══════════╤═════════╤══════════════════════════════════════════════════════╕
│"labels(p)"│"Key"    │"apoc.map.get(apoc.meta.cypher.types(p), Key, [true])"│
╞═══════════╪═════════╪══════════════════════════════════════════════════════╡
│["Person"] │"age"    │"INTEGER"                                             │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Person"] │"kids"   │"INTEGER"                                             │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Person"] │"name"   │"STRING"                                              │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Person"] │"gender" │"STRING"                                              │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Forum"]  │"name"   │"STRING"                                              │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Forum"]  │"members"│"INTEGER"                                             │
└───────────┴─────────┴──────────────────────────────────────────────────────┘

Same thing for relationships:

MATCH ()-[p]-()
WITH distinct p, keys(p) as pKeys
UNWIND pKeys as Key
RETURN distinct type(p), Key, apoc.map.get(apoc.meta.cypher.types(p), Key, [true])

Result

╒═════════╤═══════╤══════════════════════════════════════════════════════╕
│"type(p)"│"Key"  │"apoc.map.get(apoc.meta.cypher.types(p), Key, [true])"│
╞═════════╪═══════╪══════════════════════════════════════════════════════╡
│"KNOWS"  │"since"│"INTEGER"                                             │
└─────────┴───────┴──────────────────────────────────────────────────────┘

View solution in original post

1 REPLY 1

paulare
Graph Buddy

Hi, @Kailash

Are looking for something like:

MATCH (p:Person {name: 'Eve'})
WITH p
RETURN apoc.meta.cypher.types(p)

{
  "name": "STRING",
  "gender": "STRING",
  "age": "INTEGER",
  "kids": "INTEGER"
}

To get same result, each line separate:

MATCH (p)
WITH distinct p, keys(p) as pKeys
UNWIND pKeys as Key
RETURN distinct labels(p), Key, apoc.map.get(apoc.meta.cypher.types(p), Key, [true])

Result

╒═══════════╤═════════╤══════════════════════════════════════════════════════╕
│"labels(p)"│"Key"    │"apoc.map.get(apoc.meta.cypher.types(p), Key, [true])"│
╞═══════════╪═════════╪══════════════════════════════════════════════════════╡
│["Person"] │"age"    │"INTEGER"                                             │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Person"] │"kids"   │"INTEGER"                                             │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Person"] │"name"   │"STRING"                                              │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Person"] │"gender" │"STRING"                                              │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Forum"]  │"name"   │"STRING"                                              │
├───────────┼─────────┼──────────────────────────────────────────────────────┤
│["Forum"]  │"members"│"INTEGER"                                             │
└───────────┴─────────┴──────────────────────────────────────────────────────┘

Same thing for relationships:

MATCH ()-[p]-()
WITH distinct p, keys(p) as pKeys
UNWIND pKeys as Key
RETURN distinct type(p), Key, apoc.map.get(apoc.meta.cypher.types(p), Key, [true])

Result

╒═════════╤═══════╤══════════════════════════════════════════════════════╕
│"type(p)"│"Key"  │"apoc.map.get(apoc.meta.cypher.types(p), Key, [true])"│
╞═════════╪═══════╪══════════════════════════════════════════════════════╡
│"KNOWS"  │"since"│"INTEGER"                                             │
└─────────┴───────┴──────────────────────────────────────────────────────┘