0% found this document useful (0 votes)
80 views

NoSQL - PRACTICAL 7

The document discusses Neo4j, a graph database, and provides details about its features, usage, advantages, Cypher query language functions and datatypes. It also includes an example case study of how Neo4j was used for real-time fraud detection by a financial services firm. The document concludes with exercises involving querying an IPL dataset stored in Neo4j.

Uploaded by

papatel4045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

NoSQL - PRACTICAL 7

The document discusses Neo4j, a graph database, and provides details about its features, usage, advantages, Cypher query language functions and datatypes. It also includes an example case study of how Neo4j was used for real-time fraud detection by a financial services firm. The document concludes with exercises involving querying an IPL dataset stored in Neo4j.

Uploaded by

papatel4045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

22012021006_AKASH 4-CEIT(B1)

PRACTICAL -7
AIM: WORKING WITH Neo4j DATABASE.
WHAT IS Neo4j?
Neo4j is a NoSQL database. It is highly scalable and schema-free. It is the most
popular graphical database management system in the world. Neo4j is
developed by Neo Technology and is known as an ACID-compliant
transactional database with native graph processing and storage capabilities.
Neo4j is implemented in the Java language and is accessible in other languages
using the Cypher Query Language (CQL). Neo4j is much faster than traditional
databases.

WORKING OF Neo4j.
Neo4j stores and display in the form of graph. In Neo4j data is represented by
nodes and relationships between those nodes.
Neo4j database are a lot different to relationship databases such as a MS access,
SQL server, MYSQL etc. Relational databases use tables, rows, and columns to
store data. They also present data in a tabular fashion.
Neo4j doesn’t use tables, rows, or columns to store or present data.
Neo4j is best for storing data that has many interconnecting relationships. That’s
why graph databases like Neo4j have an advantage and much better at dealing
with relational data than relational databases are.
The graph model doesn't usually require a predefined schema. so, there is no
need to create the database structure before you load the data. In Neo4j, the data
is the structure. Neo4j is a "schema-optional" DBMS.
In Neo4j, there is no need to set up primary key/foreign key constraints to
predetermine which fields can have a relationship, and to which data. You just
have to define the relationships between the nodes you need.

FEATURES OF Neo4j
It supports UNIQUE constraints.
It uses native graphics storage with native GPE (Graph Processing Engine).

1
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

It supports exporting query data in JSON and XLS formats.


It provides a REST API accessible in any programming language like Java,
Spring, Scala, etc.
It provides JavaScript accessible by any MVC UI framework like Node JS.
It supports two types of Java APIs: Cypher API and Native Java API for
developing Java applications.

USAGE OF Neo4j
Use Neo4j If your database management system has too many connection
relationships then using Neo4j will be the best choice.
Neo4j is highly preferred for storing data containing many connections between
nodes.
• Social networks such as Facebook, Twitter, Instagram
• Network diagram
• Fraud detection
• Graph-based digital asset search
• Data management
• Timely product recommendation real time

ADVANTAGES OF Neo4j
• The representation of connected data is very simple.
• Retrieve, browse or browse connected data very quickly.
• It uses a simple and powerful data model.
• Easily represent semi-structured data.
• Neo4j is fast because more data is connected so it is easy to retrieve and
browse.

Neo4j CQL Functions


String: They are used to work with string literals.
2
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

Aggregation: They are used to perform some aggregation operations on query


results.
Relationship: They are used to get details of relationship such as start node, end
node, etc.

Neo4j CQL Datatypes


Boolean: It used to represent Boolean literals: True or False.
Byte: It is used to represent 8-bit integers.
Short: It used to represent 16-bit integers.
Int: It used to represent 32-bit integers.
Long: It is used to represent 64-bit integers.
Float: It is used to represent 32-bit floating-point numbers.
Double: It is used to represent 64-bit floating-point numbers.
Char: It is used to represent 16-bit characters
String: It is used to represent string.

CASE STUDY:
Neo4j Empowers Real-Time Fraud Detection for Financial Services.

CHALLENGE:

A driving monetary administrations firm confronted a developing challenge in


identifying and anticipating false exercises over its tremendous arrange of
exchanges. Conventional extortion discovery frameworks battled to keep pace
with the advancing strategies of fraudsters, coming about in noteworthy
budgetary misfortunes and harm to the firm's notoriety.

SOLUTION:
The firm turned to Neo4j to upgrade its extortion location capabilities with real-
time chart investigation. By modelling exchanges, clients, accounts, and their

3
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

connections as a chart, Neo4j empowered the firm to reveal complex designs


and associations characteristic of false behaviour.

Utilizing Neo4j's chart calculations and inquiry capabilities, the firm executed a
advanced extortion discovery framework that might distinguish suspicious
exercises in real-time. By analysing the value-based information and the
organize of connections between substances, Neo4j given significant bits of
knowledge that enabled extortion investigators to require quick and focused on
activities to moderate dangers.

RESULT:
Increased Accuracy:
Neo4j's graph-based approach altogether made strides the precision of extortion
location by recognizing unpretentious designs and peculiarities that
conventional frameworks frequently missed.

Real-Time Discovery:
With Neo4j's real-time capabilities, the firm may identify and react to false
exercises as they happened, minimizing money related misfortunes and
reputational harm.

Versatile Framework:
Neo4j's adaptable information demonstrate permitted the firm to adjust rapidly
to unused extortion plans and strategies, guaranteeing proceeded adequacy in
combating extortion.

CONCLUSION:
By leveraging Neo4j's chart database innovation, the money related
administrations firm changed its extortion location capabilities, accomplishing
more noteworthy exactness, speed, and flexibility in combating budgetary
wrongdoing. The organization with Neo4j not as it were defended the firm's
resources but moreover reinforced client believes and certainty in its
administrations.

4
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

EXERCISE
Exercise-1 (IPL DATASET)

1) Nodes where name is Rohit Sharm

QUERY: MATCH (p:PLAYER {name: 'Rohit Sharma'}) RETURN p;

OUTPUT:

2) Nodes where name is not Rohit Sharma

QUERY: MATCH (p:PLAYER) WHERE NOT p.name = 'Rohit Sharma' RETURN p;

OUTPUT:

3) Nodes where height is greater than or equal to 2

QUERY: MATCH (p:PLAYER) WHERE p.height >= 2 RETURN p;

OUTPUT:

4) Nodes where height is less than 2

QUERY: MATCH (p:PLAYER) WHERE p.height < 2 RETURN p;

OUTPUT:

5
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

5) Nodes with a BMI larger than 25

QUERY: MATCH (p:PLAYER) WHERE (p.weight / (p.height ^ 2)) > 25 RETURN p;

OUTPUT:

6) Nodes with a BMI not larger than 25

QUERY: MATCH (p:PLAYER) WHERE (p.weight / (p.height ^ 2)) <= 25 RETURN p;

OUTPUT:

7) Nodes with a weight larger than 70 and a height smaller than 120

QUERY: MATCH (p:PLAYER) WHERE p.weight > 70 AND p.height < 120 RETURN p;

OUTPUT:

8) Nodes with height greater than 2.1 or weight greater than 120

QUERY: MATCH (p:PLAYER) WHERE p.height > 2.1 OR p.weight > 120 RETURN p;

OUTPUT:

9) Get the nodes of the players with their coach.

QUERY: MATCH (player:PLAYER)-[:COACHES_FOR]->(coach) RETURN player, coach;

OUTPUT:

6
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

10) GET ALL KKR PLAYERS

QUERY: MATCH (player:PLAYER)-[:PLAYS_FOR]->(team:TEAM{name: 'KKR'}) RETURN player;

OUTPUT:

11) GET ALL KKR OR royal PLAYERS

QUERY: MATCH (player:PLAYER)-[:PLAYS_FOR]->(team:TEAM) WHERE team.name IN ['KKR', 'royal']


RETURN player;

OUTPUT:

12) GET ALL PLAYERS THAT MAKE MORE THE 35M

QUERY: MATCH (player:PLAYER)-[rel:PLAYS_FOR]->() WHERE rel.salary > 35000000 RETURN player;

OUTPUT:

13) GET ALL OF Virat’s TEAMMATES THAT MAKE MORE THAN 30M

QUERY: MATCH (virat:PLAYER {name: 'Virat Kohli'})-[:TEAMMATES]->(teammate)-[rel:PLAYS_FOR]->()


WHERE rel.salary > 30000000 RETURN teammate;

7
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

OUTPUT:

14) GET PLAYERS AND NUMBER OF GAMES PLAYED

QUERY: MATCH (player:PLAYER)-[:PLAYED_AGAINST]->() RETURN player, count(*) as gamesPlayed;

OUTPUT:

15) GET PLAYERS AND runs PER GAME

QUERY: MATCH (player:PLAYER)-[:PLAYED_AGAINST]->(opponent) RETURN player,


sum(opponent.runs) / count(opponent) as runsPerGame;

OUTPUT:

16) GET HIGHEST SCORING PLAYER IN THE Riders

QUERY: MATCH (player:PLAYER)-[:PLAYS_FOR]->(team:TEAM{name: 'Riders'})-[:PLAYED_AGAINST]-


>(opponent) RETURN player.name, sum(opponent.runs) as totalRuns ORDER BY totalRuns DESC
LIMIT 1;

OUTPUT:

Neo4j Exercise -2

Create 7 nodes in people label having properties name, department, address, age. Create 7 nodes in
film label having properties title, released year, director name. Create relationships called friend,
brother, and favourite nodes.

8
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

Making the label people and add 7 nodes:

CREATE (:People {name: 'Kushal', department: 'IT', address: 'Surat', age: 30}),

(:People {name: 'Dhruvin', department: 'HR', address: 'Vapi', age: 25}),

(:People {name: 'Krupesh', department: 'Finance', address: 'Nadiad', age: 35}),

(:People {name: 'Divy', department: 'Marketing', address: 'Anand', age: 28}),

(:People {name: 'Jay', department: 'IT', address: 'Bharuch', age: 23}),

(:People {name: 'Raman', department: 'Finance', address: 'Mahesana', age: 27}),

(:People {name: 'Aman', department: 'HR', address: 'Patan', age: 31});

Making the label film and add 7 nodes:

CREATE (:Film {title: "Inception", released_year: 2010, director_name: "Christopher Nolan"})

(:Film {title: "The Shawshank Redemption", released_year: 1994, director_name: "Frank Darabont"})

(:Film {title: "The Godfather", released_year: 1972, director_name: "Francis Ford Coppola"})

(:Film {title: "Pulp Fiction", released_year: 1994, director_name: "Quentin Tarantino"})

(:Film {title: "The Dark Knight", released_year: 2008, director_name: "Christopher Nolan"})

(:Film {title: "Forrest Gump", released_year: 1994, director_name: "Robert Zemeckis"})

(:Film {title: "Fight Club", released_year: 1999, director_name: "David Fincher"})

Making some relationships like brother, friend and favourite film.

CREATE (divy)-[:FRIEND]->(dhruvin)

CREATE (dhruvin)-[:FRIEND]->(divy)

CREATE (jay)-[:FAVOURITE]->(the_godfather)

CREATE (the_godfather)-[:FAVOURITE_OF]->(jay)

9
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

CREATE (raman)-[:BROTHER]->(aman)

CREATE (aman)-[:BROTHER]->(raman)

CREATE (aman)-[:FAVOURITE]->(inception)

CREATE (inception)-[:FAVOURITE_OF]->(aman)

1. What are the favourite movies of (Kushal)?

QUERY: MATCH (k:People {name: 'Kushal'})-[:favourite]->(f:Film) RETURN f.title;

OUTPUT:

2. Who are friends of (Dhruvin)?

QUERY: MATCH (d:People {name: 'Dhruvin'})-[:friend]->(f:People) RETURN d, f;

OUTPUT:

3. Add a property called mobile no for person (Dhruvin) and (Krupesh).

QUERY: MATCH (d:People) WHERE d.name IN ['Dhruvin', 'Krupesh'] SET d.mobile_no =


'your_mobile_number' RETURN d;

10
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

OUTPUT:

4. Remove mobile no property for person (Divy).

QUERY: MATCH (d:People {name: 'Divy'}) REMOVE d.mobile_no RETURN d;

OUTPUT

5. Delete a relationship called brother.

QUERY: MATCH (:People)-[r:brother]-(:People) DELETE r;

OUTPUT:

6. Delete a node having age 23.

QUERY: MATCH (p:People {age: 23}) DELETE p;

OUTPUT:

7. Display details of node whose name is (Jay) and age is (23).

11
NoSQL DATABASE SYSTEM
22012021006_AKASH 4-CEIT(B1)

QUERY: MATCH (p:People {name: 'Jay', age: 23}) RETURN p;

OUTPUT:

8. Display details of node having name (Dhruvin) or (Raman).

QUERY: MATCH (p:People) WHERE p.name IN ['Dhruvin', 'Raman'] RETURN p;

OUTPUT:

12
NoSQL DATABASE SYSTEM

You might also like