cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Help with creating a query that will return only the relavant nodes:

verachkaverachk
Graph Buddy

Hello everyone,

could you please help me understand how can i get a filtered graph where i would see only my 

subGraphInstance node(alpha1 dark green color) ,his connections to the InstanceCells, cellInstances connected to the functions(in read) and between themseleve?.

is there a way to take down the connection node and only connect between two orage cellInstances?

verachkaverachk_1-1658240847120.png

 

thank you,

vera.

 

3 ACCEPTED SOLUTIONS

ameyasoft
Graph Maven

Try this:

MATCH (a:subGraphInstance) where a.name = "alpha1"
CALL apoc.path.spanningTree(a,{maxLevel:5}) YIELD path
RETURN path

You can change the maxLevel number to your desired path length. Also you can filter on nodes and relationships.

View solution in original post

First, I highly recommend checking out the free courses on the graph academy site: 
Free, Self-Paced, Hands-on Online Training | Free Neo4j Courses from GraphAcademy

For removing nodes and creating relationships, you can DETACH DELETE a node which will remove the node and its relationships and create relationships where necessary. If you are importing this data, you may want to look at how you are scripting that if you want your nodes and relationships to look differently. Having the right model may help you with your queries as well.

Second, when you say "between themselves" do you mean you want to return the nodes between the CellInstances and the Functions or do you just want to return the SubGraphInstance, CellInstances, and Functions? Depending on what you actually want, you may end up taking different approaches. 

Let's say you wanted to return the green, yellow, and red cells. You may end up with a cypher query like:

(NOTE: I am not going back and forth between the screenshot to get the exact nodes / relationships / relationship depths):

MATCH (g:Green)-[:SOME_REL]->(o:Orange)-[*3]->(r:Red)
RETURN g, o, r

The * is stating a variable path length, which will depend on the relationships between your nodes. This will return disconnected nodes in the graph view but if you go to the table, you'll have a row for each combo of green, orange, and red.

If you know the source and destination, and want the nodes in between, you can use a path and return the whole path like:
(NOTE: I am not going back and forth between the screenshot to get the exact nodes / relationships / relationship depths)

MATCH p = (g:Green)-[:SOME_REL]->(o:Orange)-[*3]-(r:Red)
RETURN p

// OR to find the path from a specific Red to Green and stuff in between
MATCH p = (r:Red { property: "matches" })-[*6]-(g:Green)
RETURN p



View solution in original post

You may want to check out the documentation on virtual nodes after going through the foundations taught in the free courses. You can find the docs here:

https://neo4j.com/labs/apoc/4.1/virtual/

View solution in original post

5 REPLIES 5

ameyasoft
Graph Maven

Try this:

MATCH (a:subGraphInstance) where a.name = "alpha1"
CALL apoc.path.spanningTree(a,{maxLevel:5}) YIELD path
RETURN path

You can change the maxLevel number to your desired path length. Also you can filter on nodes and relationships.

@ameyasoft 

Thank you for you're solution, it's good but I wish I could filter in the following way:

What I want from them is to see in each only the dark green color(SubGraphInstance), the label FROM GRAPH to my orange nodes(CellInstances), from (CellInstance-orange nodes) I want to see the red nodes(Functions of these cellIntsances) with the relationship CELL_TYPE(from orange to red node), in addition I want to see from the orange node the relationship FROM_CELL, to another orange node with relationship TO_CELL.

my purpose is to to get rid of all the additional nodes like the connection(beige) nodes, and the variables of the red functions and their relationships. 

is there a way to filter this way without damaging my data? merge didn't work good for me 😞

 

First, I highly recommend checking out the free courses on the graph academy site: 
Free, Self-Paced, Hands-on Online Training | Free Neo4j Courses from GraphAcademy

For removing nodes and creating relationships, you can DETACH DELETE a node which will remove the node and its relationships and create relationships where necessary. If you are importing this data, you may want to look at how you are scripting that if you want your nodes and relationships to look differently. Having the right model may help you with your queries as well.

Second, when you say "between themselves" do you mean you want to return the nodes between the CellInstances and the Functions or do you just want to return the SubGraphInstance, CellInstances, and Functions? Depending on what you actually want, you may end up taking different approaches. 

Let's say you wanted to return the green, yellow, and red cells. You may end up with a cypher query like:

(NOTE: I am not going back and forth between the screenshot to get the exact nodes / relationships / relationship depths):

MATCH (g:Green)-[:SOME_REL]->(o:Orange)-[*3]->(r:Red)
RETURN g, o, r

The * is stating a variable path length, which will depend on the relationships between your nodes. This will return disconnected nodes in the graph view but if you go to the table, you'll have a row for each combo of green, orange, and red.

If you know the source and destination, and want the nodes in between, you can use a path and return the whole path like:
(NOTE: I am not going back and forth between the screenshot to get the exact nodes / relationships / relationship depths)

MATCH p = (g:Green)-[:SOME_REL]->(o:Orange)-[*3]-(r:Red)
RETURN p

// OR to find the path from a specific Red to Green and stuff in between
MATCH p = (r:Red { property: "matches" })-[*6]-(g:Green)
RETURN p



verachkaverachk
Graph Buddy

@kaiserbergin 

Your solution is good for me and works, I was wondering if there is a way of making it even better(for my case) which is filtering nodes between other nodes, so could  see the Green(subGraphInstance), orange and red nodes without seeing the connenction nodes(beige) and see only through my relations FROM CELL and TO CELL (from orange node to orange node) 

Vera.

You may want to check out the documentation on virtual nodes after going through the foundations taught in the free courses. You can find the docs here:

https://neo4j.com/labs/apoc/4.1/virtual/