Best Practice

Best Practice #

This page contains common interaction patterns while making use of the Northwind sample database that comes with Neo4j Desktop.

The Northwind graph data uses 5 labels (Category, Customer, Order, Product, Supplier) and 4 relationship types (ORDERS, PART_OF, PURCHASED, SUPPLIES). The relationships types connect the labels as shown in the following meta-graph.

Northwind meta-graph

See https://neo4j.com/developer/example-data/ for how to import the Northwind data into an existing Neo4j DBMS or simply create a new project with the sample data as follows:

Import Sample Project Import Northwind

Which Orders include Products of Category “Beverages”? #

This query of schema “Which X are related to Y that are related to Z " is a very typical exploration pattern. It asks for a group of nodes X that indirectly relates to a particular node Z (or set of nodes Z).

Although it asks for a result set X the typical exploration path starts the other way round, namely from Z. In our example this is the node Beverage labeled with Category. Therefore, the most efficient way to solve this query is to:

  1. Start the exploration with Category
  2. Identify Beverage (e.g. by using search and the tabular node list)
  3. Expand the node Beverage to Product
  4. Expand the Product group to Order

Note: SemSpect also perfectly allows to start from Order, expanding to Product and then to Category – the usual order you would write a Cypher query. However, you then have to filter your Category group to Beverage and afterwards propagate this restriction up to the exploration path of your root group (see propagate filters up in an exploration how to achieve this). This method requires more interaction steps and more complex computations than when starting the other way round.

Which Customer haven’t placed an Order? #

Another very common question that refers to non-existing relationships and the ability to use this characteristic for filtering – such as restrict my group to customers that only resp. not have placed an order.

A good way to deal with this query pattern is to combine SemSpect labels and label filtering. For the case of customers and existence of related orders we could proceed as follows:

  1. Start with Order
  2. Expand the Order group to Customer
  3. Save the Customer group as a SemSpect label named Customer with Order
  4. Hereafter you can use this label to restrict or exclude this particular customer via facet filtering.