13. Query, Expand, and Search
In this Session… | Before you begin… |
| To follow along:
|
Slide | |
---|---|
1 | How To GraphXR 13. Querying |
2 | 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. |
3 | We’ll open a demo project connected to a Neo4j graph database and pull its data into GraphXR for exploration. In the Projects page, click Select Demo and choose the Game of Thrones, curated by Jeffrey Lancaster demo. |
4 | Click the Game of Thrones tile to enter its project space. |
5 | We’ll need to pull data into the project space from the Neo4j database. |
6 | Let’s also look at the current database schema, to see how the categories and relationships are connected. Open the Query panel and Cypher tab and enter the query: |
7 | Use the Quick Layout menu to make the schema connections easier to see. |
8 | To see the many relationships around the Character category in more detail, double click the Character node to display its information panel, then select the Neighbors tab. |
9 | To visualize and explore this data, we’ll pull patterns into GraphXR in a few different ways: sampling, keyword search, and Cypher query. Then we’ll use GraphXR’s no-code Expand feature to pull in more data through additional relationships. |
10 | Clear the schema before pulling in data. Use Ctrl+A to select the schema, then right-click and select Delete (or use the delete key). |
11 | We can pull a sample of a selected Category or Relationship 25 nodes or edges at a time. In the Project=>Category tab, select the Character category and click Pull. |
12 | 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. |
13 | 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. |
14 | Since our demo database is configured for keyword search, we can search for property values in the Search Bar and return matching nodes. |
15 | See that the search from database icon is displayed. We’ll add nodes not yet in our graph for the House ‘Baratheon’. Enter ‘Baratheon’ in the search field. |
16 | Click the plus (+) icon to pull all nodes of the Character and House categories. You can click a single line to pull just one node. |
17 | Notice that only nodes are pulled using a search, not edges. We can use Expand to connect nodes through edges of specific relationships. |
18 | Select the nodes returned by our search, right-click and choose Expand. In the Expand with relationships dialog, choose the belongs_to relationship (and any other relationships of interest), and click Expand. |
19 | The Character nodes are now connected to their House node through belongs_to edges. Edges of any other relationships we selected and additional connected nodes are also pulled in. |
20 | Using Pull or keyword search with Expand is a quick way to start exploring patterns in the connected database. However, we also have the option of using Cypher queries to bring in more specific graph patterns as a starting point. |
21 | For example, a basic Cypher query will help us explore family relationships among characters connected to all the houses. Let’s see what a Cypher query looks like. |
22 | Go back to the Query panel and Cypher tab. First, look at the example Cypher query provided in this demo project. Click the display menu and select the query. |
23 | MATCH (n)-[r]-(m) RETURN * LIMIT 100 |
24 | It’s prudent to set a LIMIT with such a general query. Otherwise it can return a large amount of data or even time-out before completing the query. |
25 | The first 100 patterns happen to include Episode and Location nodes. Now that we’ve seen the example, let’s clear the graph and enter a more specific query. |
26 | We’ll enter a query for (Character)–[belongs_to]–(House) patterns. These will start to show us family relationships: |
27 | Click the run arrow to the right of the query. Matching patterns that include 98 total nodes are returned: 85 Character and 13 House nodes are connected through a variety of relationships. |
28 | Now click the Add to Collection icon to save the query. Saved queries are immediately available to all users of the project. |
29 | We have the option of entering a descriptive name, or we can select and copy the query itself, paste it into the Name field and click Confirm. |
30 | Click the display icon to see that the query is saved. |
31 | We’ll work with the data returned by this basic query. For more information about using Cypher, full details and free learning resources are available through Neo4j. |
32 | The query returned some relationships like killed or guarded_by that aren’t the family connections we’re interested in. Simply use the list in the legend to select them. Then press your delete key to delete them. |
33 | Now we’ll use Expand with relationships to pull additional nodes connected to our Characters nodes through a family relationship. Select Character nodes and either right-click and select Expand, or click the Expand toolbar icon. |
34 | In the Expand with relationships dialog, we can expand on all available relationships, 1000 edges at a time, or only on relationships of interest. |
35 | Click checkboxes to choose family relationships: belongs_to, parent_of, child_of, sibling_with, married_to, etc., then click Expand. |
36 | An additional 26 Character nodes are connected through the relationships we selected. If we Expand again with the same set of family relationships, we get a message that all those relationships have been fully expanded. |
37 | Select House nodes and use Quick Layout to arrange them in a Circle. Then choose Ring to arrange Character nodes in rings around the House nodes. Now that we see how the characters are related to each other, we’ll explore further. |
38 | We can always Expand on all possible relationships. However, an “inside out” workflow is often wanted, that is, where you start at one or a few nodes and expand on just the specific relationships you want to explore. |
39 | For example, select the Margaery Tyrell Character node, and the three nodes connected through the married_with relationship. Let’s Expand to see scenes and episodes that can tell the story of these characters. |
40 | Open the Expand with relationships dialog, click the character_in_scene and in_marriage_act relationships, and click Expand. |
41 | We see Scene and Marriage nodes connected to our selected Character nodes. |
42 | Now select Scene nodes, and expand on the scene_in_episode relationship to pull in the Episode nodes associated with our selected characters. |
43 | To further explore this graph, use the layouts, tables, search, and selection options we’ve learned about. And save Snapshots and/or data views as you go. |
44 | For example, select House nodes and, from the right-click Layout menu or Quick Layout toolbar menu, apply a Ring layout. Then use the legend to select nodes of various categories and left-click-drag to arrange them in the project space. |
45 | To focus on a smaller graph of interest, we can delete nodes and their connected edges at any time. They are deleted only from the graph, not the connected database. |
46 | We’ve queried a Neo4j database using Cypher, and used GraphXR’s Expand with relationships, node and edge sampling, and keyword search. |
47 | Download your snapshot archive, and save a final data view or GXRF file. |
Next Steps…
How To GraphXR: Module 14. Data Mapping.