Checkpoints
Load csv
/ 50
Create PARTOF relationships
/ 50
Getting Started with Neo4J Enterprise on Google Cloud
This lab was developed with our partner, Neo4j. Your personal information may be shared with Neo4j, the lab sponsor, if you have opted in to receive product updates, announcements, and offers in your Account Profile.
GSP1104
Overview
In this lab, you analyze the quarterly filings of asset managers with $100m+ assets under management (AUM) in a basic Enterprise version of Neo4j. These are regulatory filings made to the Securities and Exchange Commission’s (SEC) EDGAR system. You then load that data from a GCP Cloud Storage bucket into Neo4j. Thereafter, you explore the relationships of different asset managers and their holdings using the Neo4j Browser and Neo4j’s Cypher query language.
Objectives
In this lab, you:
- Connect to Neo4j
- Load data from a Google Cloud Storage bucket and import it into Neo4j
- Explore data in Neo4j
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Task 1. Connect to Neo4j
- In the GCP console, under Compute Engine, click on VM instances. You will the see Neo4j Enterprise Edition deployment.
Neo4j is accessible at port 7474.
- In your browser, go to {external-IP}:7474 where {external-IP} is replaced with the external IP from the Neo4J VM. A new window should ask you to log in.
- Complete the following fields:
- Leave Connect Url as default
- Leave Database field empty
- Leave Authentication type as Username/Password
- Username: neo4j
- Password: foobar123%'
- Click Connect.
Task 2. Move data to Neo4j
In this lab, you take data from a Google Cloud Storage bucket and import it into Neo4j.
For this portion of the lab, you work with a subset of the data. The full dataset is a year of data, however, you're only playing around with a day's worth.
-
If you want to look at the data being loaded, click the following link to download it: 2022-02-17.
-
Run a Cypher statement to load the data. Cypher is Neo4j's query language. Paste the following code in the text field at the top of the Neo4j console. LOAD CSV forms part of that and allows us to easily load CSV data:
It should resemble the following:
-
Press the blue triangle on the right to run the job. This loads the nodes and relationships from the file. The number of nodes are now loaded.
-
Once the number of nodes are loaded, click the database icon in the upper left to inspect them.
It can take a minute to populate this menu, but once it's populated, you see the nodes, relationships and properties loaded.
Task 3. Explore the data using Neo4j
There are two kinds of nodes, manager and company. Manager nodes are asset managers. Company nodes are the companies that asset managers buy shares of. Managers are related to companies by the OWNS relationship. Manager, company, and owns include properties you can inspect as well.
-
Click Manager under Node Labels to automatically generate a new cypher query.
A subset of the managers appears in the database. The query returns 25 of them. It's limited because returning too many nodes in this visualization mode can make it hard to navigate.
-
Now, click on one of the managers, it doesn't particularly matter which one. Once you click on it, it expands showing other options. Click the graph icon that appears at the bottom of the circle to expand it.
When it expands, you can see which companies this manager owns shares in. In this case, DENVER WEALTH MANAGEMENT, INC. seems to only have one holding, ISHARES RUSSELL. Note that this dataset only has holdings over $10m. Smaller holdings were filtered out in pre-processing.
-
Click on the relationship, that is, the line between the nodes, to view transaction details.
In this case, it appears the report is from 12-31-2021. 68,087 shares were purchased with a value of $20,807,000.
- At this point, take some time to explore the graph. Click on the Company node label on the left to query it.
As you play around, you may start to notice some of the structure in the graph with recurrent connections and interesting communities of managers who have similar holdings.
There is an interesting issue hiding in the dataset. Because of the way it's loaded, there are a bunch of duplicate nodes.
- Run the following query to find them:
Did you notice what happened? Different asset managers call securities slightly different things. In this case, the commonly held SPY or S&P 500 ETF has a number of different names.
Issues like these led to the creation of the CUSIP. In these filings, asset managers may enter all sorts of names, but the CUSIP will be unique. In the next section, you key off the CUSIP and resolve this issue.
Now that you have some understanding of this portion of the dataset, you can delete it. Then, load the full dataset.
- To delete all the nodes and relationships in the database, run the following command:
Now, all your data should be deleted. Note that the GUI is still caching some property keys.
Task 4. A year of data
The LOAD CSV statement you used before didn't create any indices. It also loaded the nodes and relationships simultaneously. Both of those are inefficient approaches. It was not a big deal, as the single day of data was about 57kb. However, you'll now load a full year's worth of data. That's 49.5mb of data, so you have to be a bit more efficient. You can now download the new dataset.
If you're curious, you can learn more about the intricacies of optimizing those loads by visiting Importing CSV Data into Neo4j - Developer guide and Importing CSV Data into Neo4j - Free Neo4j Courses.
You should also change the data model a bit, as it would improve the Graph Data Science (GDS) component of the lab where you create graph embedding. You then move some properties out of the OWNS relationship that was there previously, into a new node type called Holding.
First, create constraints, essentially a primary key, for the company and manager node types. Company keys should be CUSIPs. They are identifiers for securities designed to be unique. You can read more about them in the CUSIP Global Services documentation. This is a much better field to use than nameOfIssuer, as it avoids the problem of companies (like Apple or Apple, Inc.) being referred to by slightly different names.
- The manager is slightly more challenging. However, you can assume the filing Manager field is both unique and correct:
The result should resemble the following:
Now, the holding is more interesting. It needs a compound key, since a holding is unique in the context of:
- Being held by a particular filingManager
- Being a particular cusip
- Being for a particular reportOrCalendarQuarter
- You will need something with a compound key, such as:
The result should resemble the following:
Now that you have all the constraints, load your nodes. Thereafter, grab the relationships in a second pass. While you could do it in a single cypher statement, as you did above, it's more efficient to run them in series.
- Now, load the companies first. You will have a lot of duplication, since the key is CUSIP and many different rows in the csv, each representing a filing, have the same CUSIP. You therefore need to enhance the LOAD CSV statement slightly to deal with those duplicates:
The result should resemble the following:
- Now, load the Managers:
The result should resemble the following:
- Now, load the holdings:
The result should resemble the following:
You now have all the nodes loaded. Next, tie them together with relationships. You will want two kinds of relationships:
- A manager "OWNS" holdings
- Holdings are "PARTOF" companies
- So, put together the OWNS relationship first:
The result should resemble the following:
- Now, create the PARTOF relationships:
The result should resemble the following:
You've done it! You have loaded the data setup.
Congratulations!
In this lab you connected to Neo4j and imported data from GCS. You then explored the data with the Neo4J browser and Cypher queries.
Next steps/Learn more
- Check out Neo4j on the Google Cloud Marketplace!
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated April 24, 2024
Lab Last Tested April 24, 2024
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.