Showing results for 
Search instead for 
Did you mean: 

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

Graph Steward

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


I am having the same issues, I think, though in an even simpler form.

I have a relation named :OWNS and lets call the other relation :CUSTOMER and a relation named :PARTNER

And I have nodes with types (Individual:Party) and (:Organization:Party)

And I try to return the parties that own an item.

MATCH (p:Party)-[r:OWNS]->(i:Item) RETURN p, r, i

And my general understanding is that this then would return the graph with the matching elements. But I am getting other elements as well. I am getting all other nodes and relations from nodes that match the query. So if a party got an :OWNS relation then all other relations and the linked nodes that is linked to that party shows.

THough in the table mode it seems to only list the real data. Is there a configuration in neo to not print links from matched nodes unless asked for???

In the neo4j browser view, this may be the reason for seeing non-explicitly queried edges:

TLDR: The neo4j browser by default auto-completes to show all relationships that exist between nodes in the query/visualisation. This can be turned off in the settings tab (click on the gear bottom left) by unselecting "Connect result nodes".