In this Session…
Before you begin…
To follow along:
How To GraphXR 13. Querying
Before You Begin…
Ideally, you’ll have worked through Module 12. Geospatial Mapping and Tagging. If you’re starting here, and you want to follow along, you’ll need to:
We’ll use a demo project which connects GraphXR to data in a Neo4j graph database.
We’ll open a demo project connected to a Neo4j graph database and pull its data into GraphXR in various ways. (If you are in a project space, click the Home button to exit and return to the Projects page.)
Click Select Demo and choose the Game of Thrones demo.
Click the Game of Thrones tile to enter its project space.
The project graph space will be blank, since we have not yet queried for data. In the Project panel we can review the categories and relationships defined for the Neo4j database connected to this demo project.
Let’s also look at the current database schema, to see how the categories and relationships are connected to each other. Open the Query panel and Cypher tab and enter the following Cypher query:
In Project→Settings tab click Show Relationship Name. Then use Quick Layout toolbar menu to display the schema entities in a circle.
The schema includes many relationships around the Character category. To see these in more detail, double click the Character node to display its Information panel, then select the Neighbors tab.
Though our schema is complex, we can start with a simple Cypher query for Characters who belong to a House. Then we can use the no-code Expand toolbar icon to pull in additional data connected through specific relationships.
Go to the Query panel and Cypher tab. First, we’ll briefly look at the basic Cypher query provided as an example. Click the display menu and select the query.
MATCH (n)-[r]-(m) RETURN * LIMIT 100
It’s prudent to set a LIMIT with such a non-specific query; otherwise it can return a large amount of data or even time-out before completing the query.
We can also set a limit by entering Max Return records allowed. This overrides any larger limit set in the LIMIT qualifier.
MATCH (c:Character)-[r:belongs_to]-(h:House) RETURN *
Here we query for the pattern (Character) – [belongs_to] – (House).
Now click the run arrow to the right of the query to pull in data. The query returned (Character) - [belongs_to] – (House) patterns that included 98 total nodes: 85 Character and 13 House nodes.
Click the save icon to save the query. The display icon shows a dropdown menu of saved queries. For information about using Cypher, full details and free learning resources for developers are available through Neo4j.
Now that we have data in the graph space, we’ll use Expand to pull additional data connected to selected nodes. Select our Character nodes and click the Expand icon.
In the Expand with relationships dialog, you can expand on all available relationships, 1000 edges at a time. Let’s choose All and click Expand.
Now we see many additional relationships (character_in_scene, killed_by, etc.), and the nodes of additional categories that they are connected to. We’ve expanded the first 2000 relationships; there are many more than that in this graph.
We can select House nodes and apply a Quick Layout (e.g. Ring) to more easily visualize and explore this graph further.
But we may not need (or want) to see the entire graph.
For example, let’s expand on family relationships among characters in House Tully. First let’s locate those nodes. Open the Table panel, click the House category, enter ‘Tully’ in the search bar and click the search result to center on the node.
Let’s remove the other data. Select the Tully House node and its two connected Character nodes, click Inverse, and press the delete key (or Delete icon).
Now select the two connected Character nodes and open the Expand dialog.Click the sibling_with, married_to, and parent_of relationships and click Expand.
Next we can find scenes that included one or more characters. Select a Character node (e.g. Catelyn Stark), open the Expand dialog, select the character_in_scene and belongs_to relationships, and click Expand.
We now see Scene nodes and a House node associated with the selected Character node. We can delete nodes and their connected edges at any time. Let’s select the Scene nodes and press delete.
We can also pull a sample of data for a selected category or relationship 25 nodes or edges at a time. In the Project → Category tab, select the Character category and click Pull.
Character nodes are pulled from the database, along with any relationships between the pulled nodes and with nodes already in the graph. Now click the Relationship tab.
Select the belongs_to relationship and click Pull. Remember that an edge does not exist by itself - it must be connected to two nodes. So a sample of edges can pull in node categories that aren’t already in the graph.
Since our demo database is conﬁgured for keyword search, we can search for property values in the Search Bar and return matching nodes. See that the search from database icon is displayed. Enter a search term (e.g. the name ‘Lannister’).
Click the plus (+) icon to pull all nodes of a specific category, or click a single line to pull just one node. Notice that only nodes are pulled using a search, not edges.
We can use Expand to connect edges of specific relationships. With the Character nodes returned by our search pulled in and selected, open the Expand dialog, choose the belongs_to relationship, and click Expand.
We’ve queried a Neo4j database using Cypher, and used GraphXR’s Expand, sampling, and keyword search. GraphXR also supports query of graph databases using Gremlin, query and mapping a SQL table or CSV file, and query of JSON documents.
Next, in Module 14. Data Mapping, we’ll load CSV data and model it as a graph.
How To GraphXR: Module 14. Data Mapping.