Category: neo4j

  • Khóa học miễn phí Neo4j – Environment Setup nhận dự án làm có lương

    Neo4j – Environment Setup



    In this chapter, we will discuss how to install Neo4j in your system using exe file.

    Neo4j Database Server Setup with Windows exe File

    Follow the steps given below to download Neo4j into your system.

    Step 1 − Visit the Neo4j official site using . On clicking, this link will take you to the homepage of neo4j website.

    Home Page

    Step 2 − As highlighted in the above screenshot, this page has a Download button on the top right hand side. Click it.

    Step 3 − This will redirect you to the downloads page, where you can download the community edition and the enterprise edition of Neo4j. Download the community edition of the software by clicking the respective button.

    Download Page

    Step 4 − This will take you to the page where you can download community version of Neo4j software compatible with different operating systems. Download the file respective to the desired operating system.

    Respective Operating System

    This will download a file named neo4j-community_windows-x64_3_1_1.exe to your system as shown in the following screenshot.

    Community Windows

    Step 5 − Double-click the exe file to install Neo4j Server.

    Exe File

    Step 6 − Accept the license agreement and proceed with the installation. After completion of the process, you can observe that Neo4j is installed in your system.

    Starting the Server

    Step 1 − Click the Windows startmenu and start the Neo4j server by clicking the start menu shortcut for Neo4j.

    Starting Server

    Step 2 − On clicking the shortcut, you will get a window for Neo4j Community edition. By default, it selects c:Users[username]DocumentsNeo4jdefault.graphdb. If you want, you can change your path to a different directory.

    Shortcut

    Step 3 − Click the “Start” button to start the Neo4j server.

    Start Button

    Once the server starts, you can observe that the database directory is populated as shown in the following screenshot.

    Database Directory

    Working with Neo4j

    As discussed in the previous chapters, neo4j provides an in-built browse application to work with Neo4j. You can access Neo4j using the URL http://localhost:7474/

    Working

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Neo4j CQL – Creating a Relationship nhận dự án làm có lương

    Neo4j CQL – Creating a Relationship



    In Noe4j, a relationship is an element using which we connect two nodes of a graph. These relationships have direction, type, and the form patterns of data. This chapter teaches you how to −

    • Create relationships
    • Create a relationship between the existing nodes
    • Create a relationship with label and properties

    Creating Relationships

    We can create a relationship using the CREATE clause. We will specify relationship within the square braces “[ ]” depending on the direction of the relationship it is placed between hyphen “ – ” and arrow “ → ” as shown in the following syntax.

    Syntax

    Following is the syntax to create a relationship using the CREATE clause.

    CREATE (node1)-[:RelationshipType]->(node2)
    

    Example

    First of all, create two nodes Ind and Dhawan in the database, as shown below.

    CREATE (Dhawan:player{name: "Shikar Dhawan", YOB: 1985, POB: "Delhi"})
    CREATE (Ind:Country {name: "India"})
    

    Now, create a relationship named BATSMAN_OF between these two nodes as −

    CREATE (Dhawan)-[r:BATSMAN_OF]->(Ind)
    

    Finally, return both the nodes to see the created relationship.

    RETURN Dhawan, Ind
    

    Browser App

    Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.

    Highlighted Query

    Result

    On executing, you will get the following result.

    Executing

    Creating a Relationship Between the Existing Nodes

    You can also create a relationship between the existing nodes using the MATCH clause.

    Syntax

    Following is the syntax to create a relationship using the MATCH clause.

    MATCH (a:LabeofNode1), (b:LabeofNode2)
       WHERE a.name = "nameofnode1" AND b.name = " nameofnode2"
    CREATE (a)-[: Relation]->(b)
    RETURN a,b
    

    Example

    Following is a sample Cypher Query which creates a relationship using the match clause.

    MATCH (a:player), (b:Country) WHERE a.name = "Shikar Dhawan" AND b.name = "India"
    CREATE (a)-[r: BATSMAN_OF]->(b)
    RETURN a,b
    

    To execute the above query, carry out the following 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 the following 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 the following screenshot.

    Existing Node

    Result

    On executing, you will get the following result.

    Executing

    Creating a Relationship with Label and Properties

    You can create a relationship with label and properties using the CREATE clause.

    Syntax

    Following is the syntax to create a relationship with label and properties using the CREATE clause.

    CREATE (node1)-[label:Rel_Type {key1:value1, key2:value2, . . . n}]-> (node2)
    

    Example

    Following is a sample Cypher Query which creates a relationship with label and properties.

    MATCH (a:player), (b:Country) WHERE a.name = "Shikar Dhawan" AND b.name = "India"
    CREATE (a)-[r:BATSMAN_OF {Matches:5, Avg:90.75}]->(b)
    RETURN a,b
    

    To execute the above query, carry out the following 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 the following 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 the following screenshot.

    Label Property

    Result

    On executing, you will get the following result.

    Executing

    Creating a Complete Path

    In Neo4j, a path is formed using continuous relationships. A path can be created using the create clause.

    Syntax

    Following is the syntax to create a path in Neo4j using the CREATE clause.

    CREATE p = (Node1 {properties})-[:Relationship_Type]->
       (Node2 {properties})[:Relationship_Type]->(Node3 {properties})
    RETURN p
    

    Example

    To execute the above query, carry out the following 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 the following 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 the following screenshot.

    Champions Trophy

    Result

    On executing, you will get the following result.

    Result

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc