Skip nodes in a path

Hi,

I have the following scenario:

In all cases the returned path should be the one that is coloured. When the middle Service is as in Case 1, then the returned path should only consider the top and bottom level services and not the middle one. Is there any apoc procedure to skip a node in the path? Or could this be achieved with a normal Cypher statement? Thanks in advance!

I am sorry, I don’t fully understand your scenario. Are you searching for a path with a pattern and you only want paths that match the right three to return and have the left one eliminated from the result?

What do you mean by ‘skip’ the node?

Can you share any cypher code you tried?

So I would like to return the four paths but in CASE 1, I would like to return only the top and the bottom service. "Skip" is a property that shows me the node that I should consider to skip (not include in the returned path).

Sorry, I am still not clear. Do you know the start and end nodes, or are these also found by the query? For example, in the following we specify the start and end node and find the path between them that matches your pattern:

match(s1:Service{id:1})
match(s2:Service{id:2})
match p=(s1)-[:HAS_PARENT*0..999]->(s:Service)-[:HAS_PARENT*0..999]->(s2)
return p

Or, we don't know the specific nodes; only that they are 'Service' nodes. In this case, the query would be more like the following:

match p=(s1:Service)-[:HAS_PARENT*0..999]->(s:Service)-[:HAS_PARENT*0..999]->(s2:Service)
return p

It sounds more like the latter, since you want to only return the start and end nodes for case 1. Is this what you want?

What is it you actually want to return: 1) the entire path, 2) all the nodes along the path, or 3) just the start, middle, and nodes? When you state 'skip' the middle node, what does that mean?

It looks like the discriminating factor that identifies case 1 is that the start, middle, and end nodes all have 'type' equal to 'skip'. Is this true?

Since your pattern has a lower limit of '0' for number of hops in both relationships, you could get a result that consists of just one 'Service' node for the match.

Sorry for all the questions, but it will help me understand what your requirements are.

thanks for your reply. The conditions are as following:

  • return the normal/entire path between services when:
    • case 2, case 3, and case 4
  • return the modified path between services when:
    • case 1

Note that the modified path means to return only the path the contains the start and the end node, while skipping or not including the middle node. Then the path would be:
(s:Service)-[:HAS_GRANDPARENT* 0..999]->(s2:Service) ----> where the middle service is not included here. I hope that you understand better now the issue.