Index-free adjacency (IFA) is a property of Neo4j’s native graph engine that eliminates the need for complex joins and enables real-time traversals. With IFA, Neo4j stores nodes and relationships as objects that are linked to each other. Conceptually, the graph looks as follows:
Using IFA, the Neo4j query engine starts with the anchor of the query which is the Group node with the id of 3.
IFA is a key trait of a graph database that allows it to find the neighbors of any given node without having to consider the full set of relationships in the graph.
Relationship in Neo4j graph database are stored at write time while joins are computed at read time in RDBMS.
2. Graph Elements
A node will commonly represent an individual record, for example, a thing or a fact.
Nodes can have one or more labels. Labels provide a way to group nodes and also serve as a starting point for any database queries.
A relationship connects two nodes. Each relationship has exactly one start and end node. A relationship will have a single a type.
Relationships are identified by their type.
Both nodes and relationships can contain properties. A property is a key/value pair.
3. Modeling Rules
Nodes typically represent things. Examples of entities that could typically be represented as a node are: person, product, event, book or subway station.
Relationships are typically verbs. We could use a relationship to represent a personal or professional connection (Person knows Person, Person married to Person), to state a fact (Person lives in Location, Person owns Car, Person rated Movie), or even to represent a hierarchy (Parent parent of Child, Software depends on Library).
Verbs can also be nodes. A verb may be modeled as a node when one or more facts need to be associated with it. For example, you may want to group multiple product purchases through a single (:Order) node.
1. What is Graph Database?
Graph Database is a database that model the data in the form of graph. In here, the nodes of the graph represent the entities while relation depict the association of these nodes.
2. Environment Setup
Make a docker-compose.yml file and write these lines.
Neo4j Graph Database has the following building blocks:
Nodes: is a fundamental unit of a Graph. It contains properties with key value pairs.
Properties: is a key-value pair to describe Graph Nodes and Relationships.
Relationships: connects two nodes
Labes: Label associates a common name to a set of nodes or relationships. A node or relationship can contain one or more labels. We can create new labels to existing nodes or relationships. We can remove the existing labels from the existing nodes or relationships.
4. Neo4j-CQL Introduction
Is a query language for Neo4j Graph Database.
Is a declarative pattern-matching language.
Follows SQL like syntax.
Syntax is very simple and in human readable format.
Neo4j Read Clauses
Used to search the data with a specified pattern
Same as match, the only difference being it can use nulls in case of missing part of patterns
Used to add contents to the CQL queries
Used to find the starting points through the legacy indexes
Used to import data from CSV files
Neo4j Write Clauses
Used to create Nodes, Relationships, and Properties
Verifies whether specified pattern exists in the graph, If not, it creates the pattern
Used to update labels on nodes, properties on nodes and relationships
Used to delete nodes and relationships or paths
Used to remove properties and elements from nodes and relationships
Used to update the data within a list
Using the clauses CREATE and MATCH, you can get a unique pattern by matching the existing pattern and creating the missing one
Neo4j General Clauses
Used to define what to include in the query result set
Used to arrange the output of a query in order. It is used along with the clauses RETURN or WITH.
Used to limit the rows in the result to a specific value
Used to define from which row to start including the rows in the output
Used to chain the query parts together
Used to expand a list into a sequence of rows
Used to combine the result of multiple queries
Used to invoke a procedure deployed in the database
Used to work with String literals.
Used to perform some aggregation operations on CQL Query results.
Used to get details of relationships such as startnode, endnode, etc.
CQL Data Types
Data Type Usage
Used to represent Boolean literals: true, false.
Used to represent 8-bit integers.
Used to represent 16-bit integers.
Used to represent 32-bit integers.
Used to represent 64-bit integers.
Used to represent 32-bit floating-point numbers.
Used to represent 64-bit floating-point numbers.
Used to represent 16-bit characters.
Used to represent Strings.
+, -, *, /, %, ^
+, <>, <, >, <=, >=
AND, OR, XOR, NOT
+, IN, [X], [X…..Y]
matching STARTS WITH, ENDS WITH, CONSTRAINTS
Like SQL AND operator.
Like SQL OR operator.
Like SQL NOT operator.
Like SQL XOR operator.
“Equal To” operator.
“Not Equal To” operator.
“Less Than” operator.
“Greater Than” operator.
“Less Than Or Equal To” operator.
“Greater Than Or Equal To” operator.
5. Creating Nodes
Creating a single node
Create node by simply specifying the name of the node that is to be created along with the CREATE clause.