How to GraphXR
13. Query Expand and Search
In this Session...Before you begin...
* Using Cypher to query a Neo4j database., Pulling data using Expand., Pulling data by category., Pulling data using keyword search.To follow along:

* Log in to GraphXR and open the Game of Thrones Demo Project.
Slide
1How To GraphXR 13. Querying
2Before 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:

* Log in to GraphXR.


We'll use a demo project which connects GraphXR to data in a Neo4j graph database.
3We'll open a demo project connected to a Neo4j graph database (opens in a new tab) 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.)
4Click Select Demo and choose the Game of Thrones demo.
5Click the Game of Thrones tile to enter its project space.
6The 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.
7Let'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:
CALL db.schema.visualization
Then click the run arrow.
8In Project→Settings tab click Show Relationship Name. Then use Quick Layout toolbar menu to display the schema entities in a circle.
9The 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.
10Though 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.
11Go to the Query panel and Cypher tab. First, we'll briefly look at the basic Cypher (opens in a new tab) query provided as an example. Click the display menu and select the query.
12MATCH (n)-[r]-(m) RETURN * LIMIT 100
This example query will:
MATCH any pattern of nodes n and m connected by any relationship r and RETURN the first 100 found.
Click the run arrow.
13It'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.
14We can also set a limit by entering Max Return records allowed. This overrides any larger limit set in the LIMIT qualifier.
Now let's clear the graph and create our own more specific query.
15MATCH (c:Character)-[r:belongs_to]-(h:House) RETURN *

Here we query for the pattern (Character) - [belongs_to] - (House).
The variables c, r, and h can be used in further commands rather than the full category or relationship name. We'll set a limit of 100 returns in Max Returns..
16Now 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.
17Click 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 (opens in a new tab).
18Now 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.
19In the Expand with relationships dialog, you can expand on all available relationships, 1000 edges at a time. Let's choose All and click Expand.
20Now 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.
21We can select House nodes and apply a Quick Layout (e.g. Ring) to more easily visualize and explore this graph further.
22But we may not need (or want) to see the entire graph.
With Expand we also have an “inside out” workflow: we can start with one or a few nodes and expand on just the relationships we want to explore.
23For 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.
24Let'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).
25Now select the two connected Character nodes and open the Expand dialog.Click the sibling_with, married_to, and parent_of relationships and click Expand.
Note: Set Character and House name as captions in the ProjectCategory tab.
26Next 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.
27We 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.
28We 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.
29Character 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.
30Select 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.
31Since our demo database is configured 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').
32Click 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.
33We 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.
34We'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.
35Next, in Module 14. Data Mapping, we'll load CSV data and model it as a graph.