Neo4j Match Clause - Neo4j

What is the use of match clause in Neo4j?

In this chapter, we will give detailed description about Match Clause and all the functions performed using this clause.

Get All Nodes Using Match

MATCH clause of Neo4j can be used to retrieve all nodes in the Neo4j database.

Example

Before proceeding with the example, create 3 nodes and 2 relationships as shown below.

Below is the query which returns all the nodes in Neo4j database.

To execute the above query, carry out below steps

Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in below screenshot.

browser app

Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in below screenshot.

match_return

Result

executing_result

Getting All Nodes Under a Specific Label

Match clause can be used to get all the nodes under a specific label.

Syntax

Below is the syntax to get all the nodes under a specific label.

Example

Below is a sample Cypher Query, which returns all the nodes in the database under the label player.

To execute the above query, carry out below steps

Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in below screenshot.

browser app

Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in below screenshot.

n_player

Result

specific_label

Match by Relationship

Nodes can be retrieved based on relationship using the MATCH clause.

Syntax

Below is the syntax for retrieving nodes based on the relationship using the MATCH clause.

Example

Below is a sample Cypher Query to retrieve nodes based on relationship using the MATCH clause.

To execute the above query, carry out below steps

Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in below screenshot.

browser app

Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in below screenshot.

top_scorer

Result

match_relationship

Delete All Nodes

All the nodes can be deleted using MATCH clause.

Query

Below is the query to delete all the nodes in Neo4j.

To execute the above query, carry out below steps

Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in below screenshot.

browser app

Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in below screenshot.

desired_press

Result

deleted_relationship

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Neo4j Topics