Neo4j Graph Database Fundamentals · Lección

Coincidencia de patrones con Cypher MATCH

Domine la cláusula MATCH para encontrar patrones específicos de nodos y relaciones en los datos de su grafo.

Lección 3 de 411 pasos

Coincidencia de patrones con Cypher MATCH es una lección gratuita de Neo4j Graph Database Fundamentals en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Neo4j Graph Database Fundamentals, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Neo4j Graph Database Fundamentals incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Discovering Data with MATCH

Welcome to the core of graph querying! The MATCH clause in Cypher is how you find specific patterns of data in your Neo4j graph.

Think of it like drawing the shape of the data you want to find. You describe nodes, relationships, and their properties, and Neo4j finds all instances that fit your description.

Finding Any Node

The simplest MATCH query finds any node in your graph. You represent a node using parentheses ().

Adding a variable inside, like (n), lets you refer to that node later, for example, to return its properties. We'll use LIMIT to show just a few results.

MATCH (n)
RETURN n LIMIT 3

Matching Nodes by Label

Graphs often have different types of nodes. In Cypher, these types are called labels. You can specify a label to find only nodes of a particular type.

Labels are placed after the node variable, separated by a colon: (variable:Label).

MATCH (p:Person)
RETURN p.name LIMIT 3

Matching Nodes by Property

Nodes also have properties, which are key-value pairs describing them. You can filter nodes based on these properties directly within your MATCH clause.

Properties are placed inside curly braces {} after the label (or variable if no label): (node:Label {key: 'value'}).

MATCH (m:Movie {title: 'The Matrix'})
RETURN m.releaseYear

Introducing Relationships

Relationships define how nodes are connected. In MATCH, you represent a relationship using dashes and angle brackets: -- for undirected, --> for directed, and <-- for reverse directed.

You can also assign a variable to the relationship, like -[r]-, to work with it.

MATCH (a)-[r]->(b)
RETURN a.name, TYPE(r), b.title LIMIT 3

Matching Relationships by Type

Just like nodes have labels, relationships have types. Specifying a relationship type helps you find specific kinds of connections between nodes.

The type is placed after the relationship variable, separated by a colon: -[r:TYPE]->.

MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
RETURN p.name, m.title LIMIT 3

Matching with Direction

Relationships are directional! The arrows in your MATCH pattern indicate the flow. If you omit arrows (e.g., (a)-[r]-(b)), the match will be undirected, finding connections regardless of their stored direction.

It's generally best practice to specify direction when you know it.

MATCH (director:Person)<-[:DIRECTED]-(movie:Movie)
RETURN director.name, movie.title LIMIT 3

Combining Node & Relationship Patterns

The real power of MATCH comes from combining nodes and relationships to describe complex patterns in your graph. You can chain multiple nodes and relationships together.

This allows you to find paths, connections through intermediate nodes, and more.

MATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d:Person)
RETURN p.name, m.title, d.name

Finding Optional Connections

Sometimes, a part of your pattern might not always exist. OPTIONAL MATCH tries to find the pattern, but if it doesn't, the unmatched parts will be null instead of failing the whole query.

This is useful when you want to see existing connections while still returning the main node even if a specific connection is missing.

MATCH (p:Person {name: 'Keanu Reeves'})
OPTIONAL MATCH (p)-[r]->(m:Movie)
RETURN p.name, TYPE(r), m.title

Match Clause Challenge

Which Cypher MATCH clause correctly finds all movies directed by 'Quentin Tarantino'?

Recap: Mastering MATCH

Great job! You've learned the fundamental skill of finding patterns in your graph using the MATCH clause.

  • Use () for nodes, -- for relationships.
  • Specify labels (:Label) for node types and types (:TYPE) for relationships.
  • Filter by properties using {}.
  • Arrows (-->, <--) define relationship direction.
  • OPTIONAL MATCH helps find patterns that might not always exist without breaking the query.

Next, we'll explore how to refine your matched data using WHERE and ORDER BY!

Gratis para empezar

Aprende Neo4j Graph Database Fundamentals con un tutor de IA — gratis

Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.

Cursos
12
Lecciones
48

Preguntas frecuentes

¿La lección «Coincidencia de patrones con Cypher MATCH» es gratis?

Sí — el texto completo de «Coincidencia de patrones con Cypher MATCH» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Neo4j Graph Database Fundamentals, actualiza a CoddyKit PRO. El curso de Neo4j Graph Database Fundamentals incluye 4 lecciones en total.

¿Qué aprenderé en «Coincidencia de patrones con Cypher MATCH»?

Domine la cláusula MATCH para encontrar patrones específicos de nodos y relaciones en los datos de su grafo. Practicas Neo4j Graph Database Fundamentals con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Neo4j Graph Database Fundamentals?

No se requiere experiencia previa. Neo4j Graph Database Fundamentals en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.

¿Cuánto tiempo toma la lección «Coincidencia de patrones con Cypher MATCH»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Neo4j Graph Database Fundamentals?

Sí. Cada lección de Neo4j Graph Database Fundamentals incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Nodos, relaciones y propiedades
  2. Creación de datos con Cypher CREATE
  3. Coincidencia de patrones con Cypher MATCH
  4. Devolución y estructuración de resultados con RETURN
← Volver a Neo4j Graph Database Fundamentals