Stephanie
Stephanie

Reputation: 146

Neo4j: Find nodes with property name that contains string (in the property name, not the property value)

Is there a way to find all nodes with properties that have a certain string?
Eg here with "ID":

  match (n) where exists( n[".*"+"ID"]) return n

(this does not work).

Thanks!

Upvotes: 0

Views: 1571

Answers (1)

Nathan Smith
Nathan Smith

Reputation: 881

This will give you just the keys.

MATCH (n) WHERE ANY(x IN KEYS(n) WHERE x =~".*ID") RETURN n, KEYS(n) AS myKeys

This will give you just the values.

MATCH (n) WHERE ANY(x IN KEYS(n) WHERE x =~".*ID") 
RETURN n, [x IN KEYS(n) WHERE x =~".*ID" | n[x]] AS myValues

If you have apoc, this will give you the keys and the values.

MATCH (n) WHERE ANY(x IN KEYS(n) WHERE x =~".*ID") 
WITH n, [x IN KEYS(n) WHERE x =~".*ID" | x] AS myKeys
RETURN id(n) AS nodeId, apoc.map.submap(n, myKeys) as submap

Upvotes: 3

Related Questions