11

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?

Michael Oryl
  • 20,856
  • 14
  • 77
  • 117

4 Answers4

10

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.

Abshakiba
  • 363
  • 3
  • 8
  • 2
    As of 3.2.5, the option is now "Connect Result Nodes". I think the behavior is different though. – gunner_dev Sep 19 '18 at 13:41
  • I don't know about the previous behavior, but currently if you uncheck this option, none of the relationships appear...not even the ones your specify. Perhaps there is a specific (and undocumented) way they need to be specified in order to show up in this case. – Aaron Bramson Jan 08 '19 at 03:40
  • Working for me with `RETURN node, r` – stellasia Mar 27 '19 at 12:52
  • 1
    @AaronBramson I found with the 'Connect result nodes' unchecked, I now have to return the relationship node. – Douglas Wiley Nov 10 '22 at 16:14
9

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

Community
  • 1
  • 1
Michael Oryl
  • 20,856
  • 14
  • 77
  • 117
4

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.

Ant P
  • 24,820
  • 5
  • 68
  • 105
  • 4
    The answer though is to toggle off "autocomplete" in the browser. You'll see it in the bottom right of the window. – Nicole White Jul 06 '16 at 14:20
  • 9
    I am using version 3.0.1 of the neo4j browser and there is no auto-complete toggle. I have looked at all of the settings and can't find how to turn this off. – James May 31 '17 at 17:11
3

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

John Kary
  • 6,703
  • 1
  • 24
  • 24