Hello.
I have graph:
CREATE (a:Item {id: '1'}), (b:Item {id: '2'}), (c:Item {id: '3'}), (d:Item {id: '4'}), (e:Item {id: '5'})
MATCH (a:Item {id: '5'}), (b:Item {id: '4'})
CREATE (a)-[r:RELATED_TO {type: 'type1'}]->(b)
MATCH (a:Item {id: '4}), (b:Item {id: '2'})
CREATE (a)-[r:RELATED_TO {type: 'type1'}]->(b)
MATCH (a:Item {id: '4'}), (b:Item {id: '3'})
CREATE (a)-[r:RELATED_TO {type: 'type1'}]->(b)
MATCH (a:Item {id: '2'}), (b:Item {id: '1'})
CREATE (a)-[r:RELATED_TO {type: 'type1'}]->(b)
MATCH (a:Item {id: '3'}), (b:Item {id: '1'})
CREATE (a)-[r:RELATED_TO {type: 'type2'}]->(b)
I want to get all paths from given node and filter them by relationship property. So, I(thx glilienfield) write this cypher:
MATCH path = (from:Item {id: '10'})-[relations:RELATED_TO*]->(to:Item)
WHERE ALL(r IN relations WHERE r.type IN ['type1', 'type2'])
WITH {
to: to.id
path: [i in relationships(path) | {id: endNode(i).id, type: i.type}]
} as result
RETURN COLLECT(result)
This cypher returns me all possible ways from node with id 10:
[
{
"path": [
{
"id": "5",
"type": "type1"
}
],
"to": "5"
}
,
{
"path": [
{
"id": "5",
"type": "type1"
},
{
"id": "3",
"type": "type1"
}
],
"to": "3"
}
,
{
"path": [
{
"id": "5",
"type": "type1"
},
{
"id": "3",
"type": "type1"
},
{
"id": "1",
"type": "type1"
}
],
"to": "1"
}
,
{
"path": [
{
"id": "5",
"type": "type1"
},
{
"id": "2",
"type": "type1"
}
],
"to": "2"
}
,
{
"path": [
{
"id": "5",
"type": "type1"
},
{
"id": "2",
"type": "type1"
},
{
"id": "1",
"type": "type2"
}
],
"to": "1"
}
]
How can I filter this result using neo4j and return only these paths:
[
{
"path": [
{
"id": "5",
"type": "type1"
},
{
"id": "3",
"type": "type1"
},
{
"id": "1",
"type": "type1"
}
],
"to": "1"
}
,
{
"path": [
{
"id": "5",
"type": "type1"
},
{
"id": "2",
"type": "type1"
},
{
"id": "1",
"type": "type2"
}
],
"to": "1"
}
]