Neo4j - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Neo4j Querying Data

Neo4j Querying Data

shape Description

Neo4j supports more than one query language, but cypher is its main language and the most powerful method and a query data with cypher are known to something about data modeling, the structure of a graph database and queries about the basics of pattern matching. The most important keywords for creating data, match and return and also checks for other language elements with more advanced technologies that are powerful, queries using syntax. The graph database product that encounter very flexible  and cannot be used for a fixed schema for a node. That means one can add or delete and property of nodes without affecting already stored nodes. Because of that, a graph database responds well in an agile environment where course change of a product are very common. All graph databases support one or more query language to retrieve and store data. Graph database also implement the property great model. Earlier that a graph model contains nodes and relationships.

Advanced Syntax

shape Description

Here a query that has a pattern from one node that is labeled with another node. And following are the advanced syntax of quering data processing:

Advanced Syntax : Directionless Relationships

The syntax for Directionless Relationships is as follows:
MATCH (:EPISODE)-[:PREVIOUS]-(e:EPISODE) RETURN e
Here the pattern queried from one node that is labeled episode with another episode. In between, there is a previous relationship and there is no arrow present in the relationship definition.

Advanced Syntax : No Relationships Defined

The syntax for No Relationships Defined  is as follows:
MATCH (:Episode)-->(e:Episode) RETURN e
For specifying any details about relationship it is the valid syntax. It matches one episode connected to the next , but it doesn't matter which relationship is in between.

Advanced Syntax : No Relationships Name

The syntax for No Relationships Name  is as follows:
MATCH (:ACTOR)-[]->()->(P:Planet) RETURN p
Here it don't specify any details of the two relationships in this pattern. They are just defined as empty square brackets. Notice the empty node between the relationship that are connected with the some node which as anonymous.

Advanced Syntax : Number Of Hops

MATCH (:ACTOR)-[*2]->(p:Planet) RETURN p
This number of hops syntax shows the power of a graph database compared to any other type of database. Here the actor on one side and the planet on the other with a directional relationship. In this case,the name of the relationship is not relevant. Here the *2 between the brackets contains the two hops between the actor and planet. A node connected to another node with one node in between is two hops.

Advanced Syntax : Shortest Path

MATCH(earth:planet{name:"Earth"}),(gallifrey:planet{name:"Gallifrey"}), p=shortestPath((earth)-[*..15]-(gallifrey)) RETURN p
Another shortest path in the query data process will specifying two planets and request the cypher it has to return the shortest path between the 2 nodes with a maximum of 15 hops and return the path and will display the result set. The shortwest path is in three hops. The first hop is from the planet node earth to a species by a COME_FROM relationship. The species hops to a character, the doctor and the third hop is from the doctor to gallifrey. There are multiple shortest paths, the shortest path, the function will only return the first ones that is defined or else proceed with the function with ShortestPathAll.

Advanced Syntax : Optional Match

MATCH(a:Character) OPTIONAL MATCH (a)-[r:COMES_FROM]->() RETURN r
This query is a bit different because we return the relationships instead of nodes.Here a character has to be related to some other node using the COMES_FROM relationship,but the match is optional. Cypher will return the relationships but if it doesn't find one for the character,it returns null.

Summary

shape Key Points

  • Advanced Querying - Is a query language with the structure in the graph database and queries.
  • Advanced syntax - Describes the procedural syntax for graph database.