Prerequisites
Before you begin, ensure you have:- Created a Relyt ONE instance
- Connected to the database
Overview
This guide covers:- Creating and Using Graphs - Basic AGE usage
- Bulk Data Import - Importing existing table data into graphs
Example: Product Catalog Graph
Let’s model a basic product catalog using AGE. We’ll create a catalog containing collections (e.g., Spring/Summer and Fall/Winter), with each collection containing items. Items can have sub-items, and each item has its own properties, images, and attachments.
- Each entity (blue rectangle) converts to a Vertex (node)
- Each relationship converts to an Edge
- Node labels: PascalCase (e.g.,
Catalog) - Relationships: UPPER_SNAKE_CASE (e.g.,
HAS_ATTRIBUTE)
Setup
Set Search Path
Addag_catalog to your search path to simplify queries:
Create a Graph
Creating Graph Structure
You have two approaches:- Dynamic Creation: Insert vertices and edges directly; the engine auto-creates definitions
- Pre-defined Structure: Create all vertex and edge definitions before inserting data
Create Vertex and Edge Labels
Edge labels don’t specify which vertices they connect. Actual connections are determined by the data.
Writing Data
Create a Catalog Node
- Label:
Catalog - Property:
code = "C001" - Additional property:
name = "Apparel Catalog"
Using MERGE (UPSERT)
AGE doesn’t support custom indexes. Running the sameCREATE query twice creates duplicate nodes.
Use MERGE for upsert behavior:
code = "C001".
Add a Collection
Create a Collection and connect it to the Catalog:(co)-[:BELONGS_TO]->(c) clearly shows a directed relationship.
Add Items
Add multiple items to the SS22 collection:Update Items with Attributes
Add attributes as connected nodes:Edges can have properties, making them first-class citizens in the graph.
Querying Graphs
Pattern Matching
Retrieve all items in catalog C001:Variable-Length Paths
A more compact and powerful representation:Retrieve Specific Properties
Get attributes for item ISS001:Custom Return Values
Return a JSON object list:Deleting Data
Remove Labels
Delete Edges
Delete Vertices
Delete Vertices with Edges
Deleting a vertex with edges will fail:DETACH DELETE to remove both vertex and edges:
Drop a Graph
Bulk Data Import
For large datasets, inserting data one by one is inefficient. Instead, import data into relational tables first, then load into the graph.Step 1: Create and Populate Tables
Catalog Table:Step 2: Create Helper Functions
Step 3: Create Graph and Labels
Step 4: Import Vertex Data
Step 5: Import Edge Data
Step 6: Verify Data
Next Steps
This guide covers the basics of using Apache AGE with Relyt ONE. For in-depth Cypher concepts and detailed query syntax, visit the official Cypher Query Language documentation. You can also explore:- Advanced Cypher patterns and techniques
- Graph algorithms and analytics
- Performance optimization strategies
- Building production graph applications