1
votes

Is there a way to get only the nodes and relationships that are present in the Cypher query and not other relationships between nodes?

We know that nodes can have many different types of relationships between them. During analysis though, we only want to look at a specific type of relationship. the rest is clutter. Using the movie database as an example, let's use the following query.

match (p:Person)-[:ACTED_IN]->(m:Movie) 
where p.name='Tom Hanks'
return p, m;

In this query we get a nice graph of Tom Hanks and all the movies he acted in. However we also get the relationship [:DIRECTED] for the movie "That Thing You Do" which is interesting but depending on what you are analyzing, it's a distraction. I only want to display the [:ACTED_IN] relationship. Using the next query

match (p:Person)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d:Person)  
where p.name='Tom Hanks'
return p, m, d;

We get a nice view of the directors for each movie. Here though, the screen is cluttered with the [:KNOWS] relationship causing a distraction.

I know several of the data visualization products can do this, but we are in a POC and we need to get the database in first. It will be a harder sell if I have to add in a data visualization tool as well. Harder but not an impossible sell.

Currently, I am using Neo4j 3.2 but will upgrade to 3.3 for actual demo shortly.

1
My first guess is: also return the relationships, e.g. match (p:Person)-[a:ACTED_IN]->(m:Movie) where p.name='Tom Hanks' return p, a, m and turn autocomplete off by going to the bottom of the settings menu and unticking Connect result nodes.Gabor Szarnyas
thanks, this works. but I noticed that when you then double click movies you get the other actors, but double clicking out you do not get the movies, only people and the :knows relationship. Not a biggie for what I am doing just an observation.Arthur Johnson
Are movies directly connected? If they are not, you might have to keep going, i.e. double-click on a person to get additional movies. Also, I converted my comment to an answer - please accept/upvote if it worked for you.Gabor Szarnyas

1 Answers

6
votes

Is there a way to get only the nodes and relationships that are present in the Cypher query and not other relationships between nodes?

The solution involves two steps.

  1. Return the relationships, for example:

    match (p:Person)-[a:ACTED_IN]->(m:Movie)
    where p.name='Tom Hanks'
    return p, a, m
    
  2. Turn autocomplete off by going to the bottom of the settings menu and unticking Connect result nodes.