8
votes

I have a simple Neo4j graph database that I created while trying to model something for a new application. When I run the following query, I get the nodes that I am expecting, but I also get more relationships than I bargained for:

MATCH (o:Office)-[r:REPORTS_VARIABLE_TO]->() 
RETURN o,r

This is what the results look like:

Graph Query Results

Since I specifically requested things that match with [:REPORTS_VARIABLE_TO] I expected to see only that relationship in the results. What I see, though, is all relationships that exist between any matching nodes (as you can see on the bottom of the image).

Is there a way to filter out those relationships that are not of the type I'm looking for?

4

4 Answers

9
votes

So, as Nicole White was kind enough to point out, the answer is to turn off the "auto-complete" toggle in the Neo4j visualizer (bottom right hand corner, outlined in red in the image below).

This causes the app to no longer display all of the relationships between displayed/selected nodes and to only show the relationships and nodes named in the query, as demonstrated below:

enter image description here

9
votes

For the newest versions (e.g 3.2, 3.3) the "auto-complete" toggle has been moved to the browser settings and its new name is "Connected all results". If it is checked, it connects nodes with all of their relationships. Otherwise, you only see relationships which meet the filtering criteria.

4
votes

I'm pretty sure this is just a feature of the visualisation in the back-end that will display all relationships between any two nodes on the screen (note that it also displays the destination nodes even though you haven't asked for them in the return statement).

If you look at the raw query results you'll only get the relationship types you specify.

So, to put it simply: your query is perfectly valid and correct; this is just the Neo4j admin tools playing a trick on you.

0
votes

Using Neo4j Desktop 1.3.8 and the Neo4j Browser, you need to uncheck the setting "Connect result nodes".

  1. Open the Neo4j Browser for your database.
  2. Click "Browser Settings" gear icon.
  3. Scroll to bottom and uncheck "Connect result nodes"
  4. Re-run your query in the browser

Neo4j Desktop 1.3.8 Settings