Query tool

Querying data

You have learned how to import and verify your movie data in your Aura instance, creating a graph with Person and Movie nodes connected by ACTED_IN relationships.

In this lesson, you will learn: How to use the Query tool to write Cypher queries that retrieve data from your graph. You will learn query patterns that traverse relationships to find connected data.

In this lesson, you will learn how to:

  • Connect to your Aura instance using the Query tool

  • Write Cypher queries that traverse relationships

  • Visualize query results in different formats

  • Understand how relationship traversal works in graph queries

Step 1: Access the Query tool

Prerequisites: Complete the previous lesson and import the movie data into your Aura instance. You need Movie and Person nodes with ACTED_IN relationships to write recommendation queries.

How to do it:

  1. Open the Aura Console and select your instance

  2. In the left sidebar, click Query

  3. The Query tool interface opens with:

    • Sidebar: Database information showing your node labels (Movie, Person) and relationship types (ACTED_IN)

    • Cypher editor: Where you’ll write recommendation queries

    • Result frame: Where query results appear (graph, table, or text format)

Cypher is the language for traversing relationships in your graph. The Query tool lets you write and test queries interactively.

querytool_connect
querytool_start

Verify your data: Click on Movie and Person labels in the sidebar to see how many nodes you have. Click on ACTED_IN to see the relationship count. This confirms your data is ready for recommendation queries.

Step 2: Your first recommendation query

Build a query that finds all movies an actor appeared in—the foundation of actor-based recommendations.

How to do it:

  1. In the Cypher editor, type or paste this query:

    cypher
    MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)
    WHERE p.name = 'Tom Hanks'
    RETURN p, r, m
  2. Click Run (or press Ctrl+Enter)

How it works in the background: * MATCH (p:Person)-[r:ACTED_IN]→(m:Movie) - Finds all paths where a Person node connects to a Movie node via an ACTED_IN relationship * WHERE p.name = 'Tom Hanks' - Filters to only Tom Hanks * RETURN p, r, m - Returns the Person node, relationship, and Movie nodes

This query pattern (find all movies for an actor) is the first step in recommendation logic. Once you know a user likes Tom Hanks movies, you can find all his films.

querytool_command

Alternative: Use AI to generate queries

Click Generate with AI and describe what you want: "Find all movies Tom Hanks acted in". The AI generates the Cypher query for you.

Step 3: Understand your query results

The query returns a graph visualization showing Tom Hanks (Person node) connected to multiple Movie nodes via ACTED_IN relationships. Each connection represents a movie he acted in.

Seeing the connections visually helps you understand patterns. You can see how many movies an actor appeared in and identify clusters of related films.

querytool_result

Customize the visualization: Click on the labels in the Results overview panel to style your graph:

  • Colors - Make Person nodes blue and Movie nodes green for quick distinction

  • Size - Make Movie nodes larger to emphasize them in recommendations

  • Captions - Display title for Movie nodes and name for Person nodes

  • Icons - Add movie icons to Movie nodes for visual clarity

How it helps recommendations: Styled visualizations make it easier to spot patterns—like which actors appear in multiple movies together, or which movies share the most actors.

querytool_styling

Step 4: Build recommendation query patterns

Pattern 1: Find movies with the same actor

You already wrote this—finding all movies for an actor. This is the foundation of actor-based recommendations.

Pattern 2: Find actors who worked together

This query finds actors who appeared in the same movies—useful for "People who liked this actor also liked…​" recommendations:

cypher
MATCH (p1:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(p2:Person)
WHERE p1.name = 'Tom Hanks' AND p2.name <> 'Tom Hanks'
RETURN DISTINCT p2.name AS co_actor, m.title AS movie
ORDER BY co_actor

How it works: The pattern (p1)-[:ACTED_IN]→(m)←[:ACTED_IN]-(p2) finds two actors connected through the same movie. This is relationship traversal—the core of graph-based recommendations.

Pattern 3: Find similar movies (movies with shared actors)

This finds movies that share actors—the core recommendation logic:

cypher
MATCH (m1:Movie)<-[:ACTED_IN]-(p:Person)-[:ACTED_IN]->(m2:Movie)
WHERE m1.title = 'The Matrix'
RETURN DISTINCT m2.title AS similar_movie,
       COUNT(p) AS shared_actors
ORDER BY shared_actors DESC
LIMIT 10

How it works: This query traverses from a movie through actors to other movies. This demonstrates how relationship traversal works in graph databases.

These query patterns demonstrate fundamental graph traversal concepts: 1. Actor → Movies (what did this actor star in?) 2. Actor → Co-actors → Movies (what did their co-stars appear in?) 3. Movie → Actors → Similar Movies (what movies share actors?)

Query tool capabilities

The Query tool provides an interface for database interaction through Cypher:

  • Run recommendation queries: Write and test Cypher queries that traverse relationships

  • Visualize results: See actor-movie connections in graph format

  • Develop and test: Iterate on recommendation algorithms

  • Generate with AI: Use natural language to create queries

  • Administrative tasks: Create indexes to speed up recommendation queries

Step 5: Choose the right visualization format

The Query tool displays results in multiple formats. Choose the format that best supports your recommendation use case:

Graph view - Ideal for understanding relationships:

  • Use for: Seeing how actors connect to movies, identifying clusters of related films

  • Visual patterns reveal connections: Visual patterns reveal which movies share actors, making it easy to spot recommendation opportunities

  • Limitation: Works well with small to medium result sets (up to a few hundred nodes)

Table view - Use for aggregated recommendations:

  • Use for: Lists of recommended movies with counts (e.g., "Movies with 5+ shared actors")

  • Shows ranked results: Movies with more shared actors are better recommendations

  • Example: A table showing "Similar Movie | Shared Actors Count" helps you prioritize recommendations

Text/JSON view - Use for debugging and integration:

  • Use for: Debugging why a recommendation query isn’t working, or copying results for your application

  • Raw data for debugging: Raw data helps you understand query results before building recommendation APIs

When to use Query and other tools

Use the Query tool when you need to:

  • Write and test Cypher queries

  • Perform database administration (schema, indexes, constraints)

  • Debug application queries

  • Work with precise, code-based data manipulation

Consider Explore instead when:

  • Users don’t know Cypher

  • You need to visualize thousands of nodes

  • You want to share standardized views via Perspectives

Consider Dashboards instead when:

  • End users need self-service access to insights

  • You want to present aggregated metrics

  • Stakeholders need interactive reports

In the next lesson, you will explore an alternative visual approach to exploring your data.

Check your understanding

Result visualization in Query

Which result view format in the Query tool is most appropriate for visualizing relationships between nodes?

  • ❏ Table view

  • ✓ Graph view

  • ❏ Text/JSON view

  • ❏ All views show relationships equally well

Hint

Consider which format displays nodes and their connections visually rather than as rows or raw data.

Solution

The correct answer is Graph view.

The Query tool displays results in multiple formats:

  • Graph view - Visualizes relationships between nodes, showing connection patterns. Works well for small to medium result sets.

  • Table view - Displays aggregated results, property comparisons, and data for export.

  • Text/JSON view - Shows raw property values for debugging or programmatic use.

For more information, see the Neo4j Aura Query documentation.

Summary

In this lesson, you learned how to write Cypher queries using the Query tool. You:

  • Connected to your database: Used the Query tool to access your movie graph

  • Wrote recommendation queries: Learned three core patterns:

  • Finding movies for an actor

  • Finding actors who worked together

  • Finding similar movies based on shared actors

  • Visualized results: Used graph, table, and text views to understand recommendation patterns

  • Understood relationship traversal: Learned how Cypher traverses ACTED_IN relationships to find connections

These query patterns demonstrate how to traverse relationships in a graph. By traversing relationships (Person -[:ACTED_IN]→ Movie), you can find connected data, discover patterns, and explore your graph structure.

For more information on the Query tool and Cypher syntax, see the Neo4j Aura Query documentation and the Cypher Manual.

In the next lesson, you’ll explore your movie graph visually using the Explore tool, which lets you navigate actor-movie connections without writing Cypher.

Chatbot

How can I help you today?