Skip to main content
Skip table of contents

13. Query, Expand, and Search

In this Session…

Before you begin…

  • Pulling data from a connected Neo4j database by

    • category or relationship

    • keyword search

    • no-code Expand with relationships

  • Using Cypher to query a Neo4j database.

To follow along:

  • Log in to GraphXR and open the Game of Thrones Demo Project.



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:

  • Log in to GraphXR.

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 for exploration. In the Projects page, click Select Demo and choose the Game of Thrones, curated by Jeffrey Lancaster demo.


Click the Game of Thrones tile to enter its project space.


We’ll need to pull data into the project space from the Neo4j database.
But first, in the Project panel let’s review the categories and relationships already defined in our demo database.


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:
CALL db.schema.visualization
Then click the run arrow.


Use the Quick Layout menu to make the schema connections easier to see.
NOTE: If relationship names aren’t showing, go to Project=>Settings and click Show Relationship Name.


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. 


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.


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).


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.


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 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. We’ll add nodes not yet in our graph for the HouseBaratheon’.  Enter ‘Baratheon’ in the search field.


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.


Notice that only nodes are pulled using a search, not edges. We can use Expand to connect nodes through edges of specific relationships.


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.


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.


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.


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.


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.


MATCH (n)-[r]-(m)  RETURN * LIMIT 100
The demo query is a very general one that will: 
MATCH any pattern of nodes n and m connected by any relationship r, and
RETURN the first 100 found.


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. 


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.


We’ll enter a query for  (Character)–[belongs_to]–(House) patterns. These will start to show us family relationships:
MATCH (c:Character)-[r:belongs_to]-(h:House) RETURN * LIMIT 100


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.


Now click the Add to Collection icon to save the query. Saved queries are immediately available to all users of the project.


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.


Click the display icon to see that the query is saved.


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.


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.


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.


In the Expand with relationships dialog, we can expand on all available relationships, 1000 edges at a time, or only on relationships of interest.


Click checkboxes to choose family relationships: belongs_to, parent_of, child_of, sibling_with, married_to, etc., then click Expand.


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.  


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.  


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.


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.


Open the Expand with relationships dialog, click the character_in_scene and in_marriage_act relationships, and click Expand.


We see Scene and Marriage nodes connected to our selected Character nodes.


Now select Scene nodes, and expand on the scene_in_episode relationship to pull in the Episode nodes associated with our selected characters.


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.


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.


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.


We’ve queried a Neo4j database using Cypher, and used GraphXR’s Expand with relationships, node and edge 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.


Download your snapshot archive, and save a final data view or GXRF file.
Next, in Module 14. Data Mapping, we’ll load CSV data and map it as a graph.

Next Steps…

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.