0
votes

I'm a newbie in Cypher and Graph DB...I am trying to display a kind of tree from my DB, with a source node, and the downstream leaves. I would like to filter on only the leaves that have only certain labels and where all the relationships have a specific constraint on their properties. Root is a Column1 and I want to arrive on a Column1 as well, but there can be some Column2 in the path

I wrote this:

MATCH p=(:Column1{name:'Root'})-[*1..7]-(:Column1) 
WHERE 
    all(n IN nodes(p) 
        WHERE all(l in labels(n) 
                WHERE l IN ['Column1', 'Column2']
                )
        AND n.deleted='0'
        ) 
    AND all(r IN relationships(p) 
            WHERE r.deleted='0')
 RETURN p

When launched in Neo4J browser, the resulting graph is wrong and includes some relationships where deleted='1'. However, if I export the CSV table and look for deleted='1' (or even just 1), there are no result.

So it seems like the query is correct, but somehow, the graphical display will show the relationships where deleted=1.

Is it a bug, is it the query?

I also tried

MATCH (:Column1{name:'Root'})-[*1..7{deleted:'0'}]-(t)
WHERE t:Column1 or t:Column2
RETURN *

but in my DB, it takes forever to complete, compared to the previous query.

2

2 Answers

0
votes

Solved it!

I had to uncheck the "Connect Result nodes" check box in the config tab of the browser. Otherwise, it queries for all the relationships between the displayed node!

enter image description here

0
votes

Try doing

MATCH (:Column1 {name: 'Root'})-[*1..7 {deleted: '0'}]-(t)
WHERE labels(t)[0] IN ['Column1', 'Column2']
RETURN *

Depending on the amount of nodes Column1 has, and how many Column1 exists in your db, I wouldn't recommend this approach without a LIMIT 50 or whatever limit you want. If you do

PROFILE
MATCH (:Column1 {name: 'Root'})-[*1..7 {deleted: '0'}]-(t)
WHERE labels(t)[0] IN ['Column1', 'Column2']
RETURN *

You'll see just how many db hits this makes which is really resource consuming.