You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you were to represent the data in this graph in English, it might read as something like: _"Sally likes Graphs. Sally is friends with John. Sally works for Neo4j."_
69
+
If you want to represent the data in this graph in English, it would read as something like: _"Sally likes Graphs. Sally is friends with John. Sally works for Neo4j."_
70
70
71
71
Now, if you were to write this same information in Cypher, then it would look like this:
72
72
@@ -88,7 +88,7 @@ In the previous example, `Sally`, `John`, `Graphs`, and `Neo4j` are the nodes:
In Cypher, you can depict a node by surrounding it with parentheses, e.g. `(node)`.
91
+
As mentioned previously, nodes are represented as round brackets `(node)` in Cypher.
92
92
The parentheses are a representation of the circles that compose the nodes in the visualization.
93
93
94
94
==== Node labels
@@ -97,9 +97,9 @@ Nodes can be grouped together through a <<label>>.
97
97
They work like tags and allow you to specify certain types of entities to look for or to create.
98
98
Labels also help Cypher distinguish between entities and optimize execution for your queries.
99
99
100
-
In the example, both `Sally` and `John` can be grouped under a `Person` label, `Graphs` can receive a `Technology` label, and `Neo4j` can be labeled as `Company`:
100
+
In the example, both `Sally` and `John` are persons, so they get a `Person` label, `Graphs` gets a `Technology` label, and `Neo4j` is a `Company`:
101
101
102
-
.Nodes grouped in labels. Note that `Sally`, `John`, `Graphs`, and `Neo4j` are now xref:cypher/index.adoc#cypher-properties[properties] instead.
102
+
.Nodes grouped by labels. Note that `Sally`, `John`, `Graphs`, and `Neo4j` are now xref:cypher/index.adoc#cypher-properties[properties] instead.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/cypher/intro-tutorial.adoc
+26-23Lines changed: 26 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ You will create a graph, find nodes, query patterns, and solve questions about t
7
7
8
8
== Create the Movie Graph
9
9
10
-
After you create a link:https://neo4j.com/product/auradb/?ref=docs-nav-get-started[free Aura instance], select the "Connect" button and go to "Query".
11
-
In the query pane, write the following code:
10
+
After you create a link:https://neo4j.com/product/auradb/?ref=docs-nav-get-started[free Aura instance], use the "Connect" button and select "Query".
11
+
In the Cypher editor, copy and paste the following Cypher and execute the query:
12
12
13
13
[source,cypher]
14
14
--
@@ -700,21 +700,23 @@ WHERE cloudAtlas.title = "Cloud Atlas"
700
700
RETURN cloudAtlas
701
701
--
702
702
703
-
=== An amount of people
703
+
=== Limit returned results
704
704
705
-
If you want to find the names of 10 people in the graph, no matter in what order, you need to `LIMIT` the `RETURN` answers to your `MATCH` query: This code finds all _Person_ nodes in the graph but just returns the _name_ property value for 10 of them.
705
+
If you want to limit the number of returned results without any specific order, you can add `LIMIT` to the `RETURN` clause.
706
+
This query finds all the `Person` nodes in the graph and returns 10 of them using the `name` property.
706
707
707
708
[source, cypher]
708
709
--
709
-
MATCH (people:Person)
710
-
RETURN people.name LIMIT 10
710
+
MATCH (p:Person)
711
+
RETURN p.name LIMIT 10
711
712
--
712
713
713
714
For this query, property values are returned and you can only view the results as a table.
714
715
715
-
=== Movies after release year
716
+
=== The `WHERE` subclause
716
717
717
-
You can specify a range of values for selecting the `Movie` nodes to retrieve, either by specifically pointing the year:
718
+
If you want to return nodes by a specific property, you can use the `WHERE` subclause.
719
+
You can either return a specific value, in this case movies released in one specific year:
718
720
719
721
[source, cypher]
720
722
--
@@ -723,7 +725,7 @@ WHERE nineties.released = 1990
723
725
RETURN nineties.title
724
726
--
725
727
726
-
Or with a range:
728
+
Or within a range:
727
729
728
730
[source, cypher]
729
731
--
@@ -749,8 +751,8 @@ For the first query, the result is "Joe Versus the Volcano", and for the second:
749
751
750
752
== Find patterns
751
753
752
-
On the previous step, you have queried the graph for nodes.
753
-
Now you will retrieve related nodes by finding the xref:cypher/patterns.adoc[patterns] within the graph, that is, how these nodes interact with each other through relationships.
754
+
In the previous step, you queried the graph for nodes.
755
+
Now you are going to retrieve related nodes by finding the xref:cypher/patterns.adoc[patterns] within the graph, that is, how these nodes are related to each other.
754
756
755
757
=== All Tom Hanks movies
756
758
@@ -766,12 +768,12 @@ This is the result:
766
768
767
769
image::tomhanksmovies.svg[Result to the query searching for all movies that Tom Hanks has acted in, width=500, role="popup-link"]
768
770
769
-
Note that Tom Hanks' node is connected to `Movie` nodes through two different relationships: `ACTED_IN` and `DIRECTED`, which means some people listed in the `Person` nodes can be both actors and directors.
771
+
Note that Tom Hanks' node is connected to `Movie` nodes through two different relationships: `ACTED_IN` and `DIRECTED`, which means a `Person` node can be both an actor and a director.
770
772
771
773
=== Directors of "Cloud Atlas"
772
774
773
775
As mentioned previously, you can find information about directors through the relationship `DIRECTED`.
774
-
To learn who directed "Cloud Atlas", you can write the following query:
776
+
To learn who directed "Cloud Atlas", execute the following query:
775
777
776
778
[source, cypher]
777
779
--
@@ -792,7 +794,7 @@ Here is the result:
792
794
793
795
=== Tom Hanks' co-actors
794
796
795
-
This is the query you would write to get the answer:
797
+
If you want to expand the pattern and find actors who worked on the same movie, you can use the following query:
796
798
797
799
[source, cypher]
798
800
--
@@ -814,13 +816,13 @@ Then, combine with people who acted in those same movies:
814
816
MATCH (m)<-[b:ACTED_IN]-(coActors:Person)
815
817
--
816
818
817
-
This is how your graph should look like:
819
+
This is what your graph should look like:
818
820
819
821
image::tomhankscoactors.svg[Actors who played in the same movies as Tom Hanks, link="{imagesdir}/tomhankscoactors.svg",role="popup-link"]
820
822
821
823
=== People related to "Cloud Atlas"
822
824
823
-
Supposing that you don't know what relationships connect the `Person` and `Movie` nodes, you can query the graph to discover that:
825
+
If you don't know what relationships connect the `Person` and `Movie` nodes, you can query the graph to discover that:
824
826
825
827
[source, cypher]
826
828
--
@@ -834,7 +836,7 @@ Then, in the `RETURN` line, you can specify what property you want to retrieve i
834
836
In Cypher, you can define what specific propety you want to retrieve by combining the variable and the name of the property.
835
837
So, in this case, `people` is the variable for `Person` nodes and `name` is the property that stores the name of the people, thus `people.name`.
836
838
837
-
Then, since the relationships are not specified, you can use the link:https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-type[`type()` function] to retrieve the string associated to the relationship, and then `relatedTo` to also retrieve the properties associated to the relationship (e.g. `roles` in the case of `:ACTED_IN`).
839
+
Then, since the relationships are not specified, you can use the link:https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-type[`type()` function] to retrieve the relationship type, and then `relatedTo` to also retrieve all the properties associated to the relationship (e.g. `roles` in the case of `:ACTED_IN`).
838
840
839
841
Here is the result:
840
842
@@ -859,15 +861,16 @@ Here is the result:
859
861
860
862
=== Movies and actors up to three hops away from Kevin Bacon
861
863
862
-
The premise of the game "Six Degrees of Kevin Bacon" is that players need to link any actor to Kevin Bacon through their film co-stars in six or fewer steps.
863
-
You can do the same with this graph using a shortest path query that will be here referred as the "Bacon Path".
864
+
The premise of the game "Six Degrees of Kevin Bacon" is to link any actor to Kevin Bacon through their film co-stars in six or fewer steps.
865
+
This game can be played in the Movie graph using different strategies.
864
866
865
-
To perform this type of query, you need to specify:
This first query aims to find all movies and/or people who are up to 3 hops away from Kevin Bacon in the graph:
872
+
The first strategy is to use a variable length pattern.
873
+
This query finds all `Person` and `Movie` nodes one to three hops away from Kevin Bacon:
871
874
872
875
[source, cypher]
873
876
--
@@ -886,7 +889,7 @@ Here is the result of this query:
886
889
image::kevinthreehops.svg[Result to query for what movies and actors are related to Kevin Bacon, link="{imagesdir}/kevinthreehops.svg",role="popup-link"]
887
890
888
891
The downside of this query is that you don't know _how_ Kevin Bacon is related to these people and movies.
889
-
If you want to retrieve the relationships connecting these nodes, you need to write the following code:
892
+
If you want to retrieve the path that connects these nodes, `MATCH` the *path* and return it along with the `Person` or `Movie` nodes involved:
890
893
891
894
[source, cypher]
892
895
--
@@ -896,7 +899,7 @@ RETURN DISTINCT bacon, hollywood, p
896
899
897
900
Here you turn a whole line into a single variable (`p`), so that you can quote it back in `RETURN DISTINCT`, and also retrieve the relationships that connect all of these nodes.
898
901
899
-
Here is how the graph should look like now:
902
+
Here is what the graph should look like now:
900
903
901
904
image::kevinthreehopsrel.svg[Three hops from Kevin Bacon and other actors and movies, now connected through acted in, directed and produced relationships, link="{imagesdir}/kevinthreehopsrel.svg",role="popup-link"]
0 commit comments