Mencocokkan Pola dengan Cypher MATCH
Kuasai klausa MATCH untuk menemukan pola node dan relasi tertentu dalam data graf Anda.
Mencocokkan Pola dengan Cypher MATCH adalah pelajaran Neo4j Graph Database Fundamentals gratis di CoddyKit. Ini adalah pelajaran 3 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Neo4j Graph Database Fundamentals, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Neo4j Graph Database Fundamentals mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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 3Matching 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 3Matching 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.releaseYearIntroducing 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 3Matching 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 3Matching 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 3Combining 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.nameFinding 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.titleMatch 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 MATCHhelps 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!
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Mencocokkan Pola dengan Cypher MATCH” gratis?
Ya — teks lengkap “Mencocokkan Pola dengan Cypher MATCH” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Neo4j Graph Database Fundamentals, upgrade ke CoddyKit PRO. Kursus Neo4j Graph Database Fundamentals mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Mencocokkan Pola dengan Cypher MATCH”?
Kuasai klausa MATCH untuk menemukan pola node dan relasi tertentu dalam data graf Anda. Kamu berlatih Neo4j Graph Database Fundamentals dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Neo4j Graph Database Fundamentals?
Tidak diperlukan pengalaman sebelumnya. Neo4j Graph Database Fundamentals di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 3 dari 4.
Berapa lama pelajaran “Mencocokkan Pola dengan Cypher MATCH” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Neo4j Graph Database Fundamentals ini?
Ya. Setiap pelajaran Neo4j Graph Database Fundamentals menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Node, Relasi, dan Properti
- Membuat Data dengan Cypher CREATE
- Mencocokkan Pola dengan Cypher MATCH
- Mengembalikan dan Membentuk Hasil dengan RETURN