Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-03-2018 01:24 AM
Hello,
I would like to ask if there is a way to filter a specific level in a path.
eg. MATCH p=(n {name:'John'})-[:KNOWS]->(level 1)-[:ADDRESS]->(level 2)-[:COUNTRY]->(level 3) RETURN p;
I would like to filter the level 1 and return only the level 2, level 3 (all the following levels).
thank you
Solved! Go to Solution.
10-03-2018 04:17 AM
Re,
It's possible to do, but you can have some bad impact on the performances :
MATCH p=(n {name:'John'})-[:KNOWS]->(level 1)-[:ADDRESS]->(level 2)-[:COUNTRY]->(level 3)
WHERE head(tail(nodes(p))).value = 'XXXX' // your level 1 filter
RETURN tail(tail(nodes(p))), tail(tail(relationships(p))) // return all the level except the root and lvl1
In the WHERE
clause, Neo4j is working on an array, so it can't use any indexes.
10-03-2018 03:13 AM
Hi Michael,
Why are you defining a path if you don't want to use it ?
From what I understand, your query can be written like that :
MATCH (n {name:'John'})-[:KNOWS]->(lvl1)-[:ADDRESS]->(lvl2)-[:COUNTRY]->(lvl3)
WHERE lvl1.value = 'XXXX' / /your level 1 filter
RETURN lvl2, lvl3 // return only the level 2, level 3
Cheers
10-03-2018 04:04 AM
Hello,
The problem is that this query is dynamically generated so I don't know in advance which level should be filtered and on which value I should filter (defined by a user).
I want to use a path because I need to return all nodes and relations from the given pattern, except a given level so I could explicitly define a query:
MATCH (n {name:'John'})-[r1:KNOWS]->(level 1)-[r2:ADDRESS]->(level 2)-[r3:COUNTRY]->(level 3) RETURN r2, level2, r3, level3;
but I would like to ask if there is a way to do the same thing while using the path (return only path) because it simplifies the result parsing for me.
Thank you,
Michael
10-03-2018 04:17 AM
Re,
It's possible to do, but you can have some bad impact on the performances :
MATCH p=(n {name:'John'})-[:KNOWS]->(level 1)-[:ADDRESS]->(level 2)-[:COUNTRY]->(level 3)
WHERE head(tail(nodes(p))).value = 'XXXX' // your level 1 filter
RETURN tail(tail(nodes(p))), tail(tail(relationships(p))) // return all the level except the root and lvl1
In the WHERE
clause, Neo4j is working on an array, so it can't use any indexes.
All the sessions of the conference are now available online