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 filter virtual nodes/relationships after apoc.meta.graph() call?

I'd like to filter some of the nodes (or relationships) from the meta graph.

If I just call apoc.meta.graph(), the resulting nodes (and relationships) seem to have properties:

"nodes": [
{
  "identity": -1826,
  "labels": [
    "A"
  ],
  "properties": {
"name": "A",
"count": 21
  }
}
...
]

However, the following query fails to select the nodes without name "A", but results in no nodes at all.

call apoc.meta.graph()
yield nodes, relationships
with [x in nodes | x.name <> "A"] as nodes, relationships
return nodes, relationships

I also tried x.properties.name or x["properties]["name"], but all result in no nodes at all. So it seems that these virtual nodes don't seem to have any properties.

Any ideas on how to properly filter nodes (or relationships) from the meta graph?

Thx, Koen

1 ACCEPTED SOLUTION

@koen.smets
The apoc.meta.graph returns a virtual graph, therefore the "classic" neo4j methods don't work.
You have to use the apoc.any.properties or the apoc.any.property.
See here: apoc.any - APOC Documentation

For example:

call apoc.meta.graph()
yield nodes, relationships
with [x in nodes where apoc.any.properties(x).name <> "A"] as nodes, relationships
return nodes, relationships

or, filtering both nodes and rels:

call apoc.meta.graph()
yield nodes, relationships
with [x in nodes where apoc.any.property(x, 'name') <> "A"] as nodes, [x in relationships where apoc.any.property(x, 'type') <> "E"] as relationships
return nodes, relationships

View solution in original post

2 REPLIES 2

@koen.smets
The apoc.meta.graph returns a virtual graph, therefore the "classic" neo4j methods don't work.
You have to use the apoc.any.properties or the apoc.any.property.
See here: apoc.any - APOC Documentation

For example:

call apoc.meta.graph()
yield nodes, relationships
with [x in nodes where apoc.any.properties(x).name <> "A"] as nodes, relationships
return nodes, relationships

or, filtering both nodes and rels:

call apoc.meta.graph()
yield nodes, relationships
with [x in nodes where apoc.any.property(x, 'name') <> "A"] as nodes, [x in relationships where apoc.any.property(x, 'type') <> "E"] as relationships
return nodes, relationships