Is it possible to return only the edges that are specified and not the ones between the nodes of a specific type?

So given a query like the following:

MATCH (x:A {custom_id:0})-[r]-(y:B)-[:SUBTYPE]->(z:B { name: "Zed"}) RETURN x,r,y

I would like the graph to return literally:

  • the node x
  • the nodes that match y
  • and all the relationships between x and y

however I also get the relationships between all the ys which in my case tend to be many. Is it not possible to filter those edges out somehow?


Something like this should do the trick:

MATCH (x:A)-[r]-(y:B)-[:SUBTYPE]->(z:B {name:"Zed"}) RETURN x, collect(r)

x: the node x
collect(r): all the relationships between x and y

If you want the list of x, you can collect them:)

I hope it helps:)

It does not work, more specifically:

  • if i have ... RETURN x, collect(r) then I only get the x and edges it has with itself.
  • if i have ... RETURN x, collect(r), y then I get the same as OP

What you want to return is ambiguous:

  • are they only one or several nodes x?
  • the nodes that match y, so you want the list of x nodes?
  • all the relationships between x and y, so you want the list of r or all the path (x-a-y)?

I see, my bad, in my efforts to simply and make it abstract I must have missed some details. Let me clarify:

  • There is a single node x (i will update the OP)
  • I would rather have them on the graph (via neo4j browser)
  • I would like to have the edges from (x-r-y), but not (y-r'-z)

Ok, so something like this should be better:

MATCH p=(x:A)-[r]-(y:B)
WHERE (y)-[:SUBTYPE]->(z:B {name:"Zed"})

I am getting the same output. I cant really post a screenshot but essentially I am matching one node for x and three nodes for y (let's call them y1, y2, y3). With these nodes, I would like to get the edges (x-y1), (x-y2), and (x-y3), but none of the (y1-y2), (y1-y3) and (y2-y3). Is that possible?

Also what is the difference between:

MATCH p=(x:A {custom_id:0})-[r]-(y:B)
WHERE (y)-[:SUBTYPE]->(z:B {name:"Zed"})


MATCH (x:A {custom_id:0})-[r]-(y:B)-[:SUBTYPE]->(z:B {name: "Zed"}) RETURN x,r,y

Hi @ukirik,

Welcome to the community..

In your query you have not specified the direction of r. Also I hope there is only one type of relationship between A and B

There isn't one but rather multiple different types of relationships we capture in the graph between nodes of type A and type B, all equally interesting in this case. The directionality is important for the for the SUBTYPE relationship between the nodes of type B

In that case you will definitely get high number of nodes of Label B. If you are available we can discuss on skype.

Also have a look into