-
Notifications
You must be signed in to change notification settings - Fork 7
/
Fundamentals of Neo4j - LONG.Rpres
1516 lines (1176 loc) · 28.8 KB
/
Fundamentals of Neo4j - LONG.Rpres
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Fundamentals of Neo4j
========================================================
author:
date:
width: 1400
height: 1000
```{r, echo=FALSE}
library(RNeo4j)
file = 'import.txt'
data = readChar(file, file.info(file)$size)
graph = startGraph("http://localhost:7474/db/data/")
clear(graph, input = F)
tx = newTransaction(graph)
appendCypher(tx, data)
commit(tx)
printError = function(query) {
err = try(cypher(graph, query), silent=T)
err = strsplit(err, "\n")[[1]]
err = err[3:length(err)]
cat(paste(err, collapse="\n"))
}
printResult = function(query) {
print(cypher(graph, query), row.names = F)
}
testNonTabular = function(query) {
invisible(getNodes(graph, query))
}
```
Today's Data & Slides
========================================================
# `bit.ly/dfw-data`
# `bit.ly/dfw-slides-long`
Agenda
========================================================
- Cypher: Syntax Basics
- Cypher: Match & Return
- Cypher: Create, Merge & Delete
- Cypher: Constraints & Indexes
- Cypher: LOAD CSV
Section Header
========================================================
title: false
# Cypher: Syntax Basics
Drawing Graph Patterns
========================================================
### Nodes
`()`
### Relationships
`[]`
### Paths
`()-[]-()`
`()-[]->()`
`()<-[]-()`
Identifiers, Node Labels, & Relationship Types
========================================================
### Query
```
MATCH (t:Terminal)
RETURN t
```
### Notes
- `t` is an identifier
- `Terminal` is a node label
Identifiers, Node Labels, & Relationship Types
========================================================
### Query
```
MATCH (x:Terminal)
RETURN x
```
### Notes
- Identifiers can be whatever you want
- This query and the query from the previous slide are identical in terms of output
Identifiers, Node Labels, & Relationship Types
========================================================
### Query
```
MATCH (g:Gate)-[r:IN_TERMINAL]->(t:Terminal)
RETURN g, r, t
```
### Notes
- `g`, `r`, and `t` are identifiers
- `Gate` and `Terminal` are node labels
- `IN_TERMINAL` is a relationship type
Identifiers, Node Labels, & Relationship Types
========================================================
### Query
```
MATCH p = (:Gate)-[:IN_TERMINAL]->(:Terminal)
RETURN p
```
### Notes
- `p` is an identifier
- `Gate` and `Terminal` are node labels
- `IN_TERMINAL` is a relationship type
- The identifiers `g`, `r`, and `t` are no longer necessary; the entire path has been assigned to the identifier `p`
- This query and the query from the previous slide are identical in terms of output
Graph versus Tabular Results
========================================================
### Graph Result
#### Query
```
MATCH (t:Terminal)
RETURN t
```
#### Notes
- Returning the identifier `t` returns the node entity
- This query will return a graph in the Neo4j Browser
### Tabular Result
#### Query
```
MATCH (t:Terminal)
RETURN t.name
```
#### Notes
- Properties are accessed with `{identifier}.{property}`
- This query will return a table in the Neo4j Browser
Case Sensitivity
========================================================
### Case Sensitive
- Node labels
- Relationship types
- Property keys
### Case Insensitive
- Cypher keywords
Section Header
========================================================
title: false
# Cypher: Match & Return
Aliasing in the RETURN Clause
========================================================
**Category names.**
```{r, echo=FALSE}
query =
"MATCH (c:Category)
RETURN c.name AS category"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Results
```{r, echo=FALSE}
printResult(query)
```
The WHERE Clause
========================================================
**Names of barbecue places.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(c:Category)
WHERE c.name = 'Barbecue'
RETURN p.name AS barbecue"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Results
```{r, echo=FALSE}
printResult(query)
```
Shorthand WHERE Conditioning
========================================================
**Names of barbecue places.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(:Category {name:'Barbecue'})
RETURN p.name AS barbecue"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Regular Expressions
========================================================
**Names of bar or barbecue places.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(c:Category)
WHERE c.name =~ 'Bar.*'
RETURN p.name AS place, c.name AS category"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The STARTS WITH Clause
========================================================
**Names of bar or barbecue places.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(c:Category)
WHERE c.name STARTS WITH 'Bar'
RETURN p.name AS place, c.name AS category"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Aggregation
========================================================
**Categories and the count of how many places are in that category.**
```{r, echo=FALSE}
query =
"MATCH (:Place)-[:IN_CATEGORY]->(c:Category)
RETURN c.name AS category, COUNT(*) AS places"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The ORDER BY and LIMIT Clauses
========================================================
**Top five categories ordered descending by the count of how many places are in that category.**
```{r, echo=FALSE}
query =
"MATCH (:Place)-[:IN_CATEGORY]->(c:Category)
RETURN c.name AS category, COUNT(*) AS places
ORDER BY places DESC
LIMIT 5"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Lab
========================================================
**List the bars in alphabetical order.**
Lab
========================================================
**List the bars in alphabetical order.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(c:Category)
WHERE c.name = 'Bar'
RETURN p.name AS place
ORDER BY place"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Multiple Patterns in the MATCH Clause
========================================================
**The gate number of where the bars are located.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(c:Category),
(p)-[:AT_GATE]->(g:Gate)
WHERE c.name = 'Bar'
RETURN p.name AS place, g.number AS gate
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Multiple Patterns in the MATCH Clause
========================================================
**The gate number and terminal of where the bars are located.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(c:Category),
(p)-[:AT_GATE]->(g:Gate),
(g)-[:IN_TERMINAL]->(t:Terminal)
WHERE c.name = 'Bar'
RETURN p.name AS place, g.number AS gate, t.name AS terminal
ORDER BY place
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Multiple Patterns in the MATCH Clause
========================================================
**The closest coffee place to gate 10 in terminal B.**
```{r, echo=FALSE}
query =
"MATCH (p:Place)-[:IN_CATEGORY]->(c:Category),
(p)-[:AT_GATE]->(g:Gate),
(g)-[:IN_TERMINAL]->(t:Terminal)
WHERE c.name = 'Coffee' AND t.name = 'B'
RETURN p.name AS place,
ABS(g.number - 10) AS distance,
g.number AS gate,
t.name AS terminal
ORDER BY distance
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Lab
========================================================
**Find all of the Dunkin Donuts locations. Return the terminal and gate.**
Lab
========================================================
**Find all of the Dunkin Donuts locations. Return the terminal and gate.**
```{r, echo=FALSE}
query =
"MATCH (donuts:Place {name:'Dunkin Donuts'}),
(donuts)-[:AT_GATE]->(g:Gate),
(g)-[:IN_TERMINAL]->(t:Terminal)
RETURN t.name AS terminal, g.number AS gate
ORDER BY terminal, gate
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Negating Patterns in the WHERE Clause
========================================================
**Pairs of users who have both liked Blimpie but are not friends.**
```{r, echo=FALSE}
query =
"MATCH (u1:User)-[:LIKED]->(p:Place)<-[:LIKED]-(u2:User)
WHERE p.name = 'Blimpie' AND NOT (u1)-[:FRIENDS_WITH]-(u2)
RETURN u1, u2, p
"
```
### Query
```{r, echo=FALSE}
cat(query)
testNonTabular(query)
```
Lab
========================================================
**Find places that Alice has liked but not checked into.**
Lab
========================================================
**Find places that Alice has liked but not checked into.**
```{r, echo=FALSE}
query =
"MATCH (alice:User)-[:LIKED]->(p:Place)
WHERE alice.name = 'Alice' AND NOT (alice)-[:CHECKED_INTO]->(p)
RETURN p.name AS place
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The OPTIONAL MATCH Clause
========================================================
**Users and how many friends they have. If using MATCH, only users who have at least one friend are returned.**
```{r, echo=FALSE}
query = "MATCH (u:User)-[:FRIENDS_WITH]-(f:User)
RETURN u.name AS user, COUNT(f) AS friends
ORDER BY friends DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The OPTIONAL MATCH Clause
========================================================
**Users and how many friends they have. If using OPTIONAL MATCH, all users are returned, including users who have no friends.**
```{r, echo=FALSE}
query = "MATCH (u:User)
OPTIONAL MATCH (u)-[:FRIENDS_WITH]-(f:User)
RETURN u.name AS user, COUNT(f) AS friends
ORDER BY friends DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The SIZE Function
========================================================
```{r, echo=FALSE}
query = "MATCH (u:User)
RETURN u.name AS user, SIZE((u)-[:FRIENDS_WITH]-()) AS friends
ORDER BY friends DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The COLLECT Function
========================================================
**Users and how many friends they have, along with the names of those friends.**
```{r, echo=FALSE}
query = "MATCH (u:User)
OPTIONAL MATCH (u)-[:FRIENDS_WITH]-(f:User)
RETURN u.name AS user,
COUNT(f) AS friends,
COLLECT(f.name) AS friends_names
ORDER BY friends DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The WITH Clause
========================================================
**Users and how many friends they have, along with the names of those friends. Return only users with 2 or more friends.**
```{r, echo=FALSE}
query = "MATCH (u:User)-[:FRIENDS_WITH]-(f:User)
WITH u.name AS user,
COUNT(f) AS friends,
COLLECT(f.name) AS friends_names
WHERE friends >= 2
RETURN user, friends, friends_names
ORDER BY friends DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
The WITH Clause
========================================================
**Users and how many friends they have, along with the names of those friends.**
**Return only users with 2 or more friends and who are friends with Hank.**
```{r, echo=FALSE}
query = "MATCH (u:User)-[:FRIENDS_WITH]-(f:User)
WITH u.name AS user,
COUNT(f) AS friends,
COLLECT(f.name) AS friends_names
WHERE friends >= 2 AND 'Hank' IN friends_names
RETURN user, friends, friends_names
ORDER BY friends DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
OR with Relationship Types
========================================================
**Fast food places that Alice has either liked or checked into.**
```{r, echo=FALSE}
query =
"MATCH (alice:User)-[r:LIKED|CHECKED_INTO]->(place:Place),
(place)-[:IN_CATEGORY]->(c:Category)
WHERE alice.name = 'Alice' AND c.name = 'Fast Food'
RETURN place.name AS place, COLLECT(TYPE(r)) AS type
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Relationship Properties
========================================================
**The places that Alice has liked and the score she gave the place.**
```{r, echo=FALSE}
query =
"MATCH (alice:User)-[r:LIKED]->(p:Place)
WHERE alice.name = 'Alice'
RETURN p.name AS place, r.score AS score
ORDER BY score DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Recommendations
========================================================
**Fast food or dessert & snack places that Alice's friends have liked ordered by the average score her friends gave the place.**
**Alice can't have already liked or checked into the place.**
```{r, echo=FALSE}
query =
"MATCH (alice:User)-[:FRIENDS_WITH]-(friend:User),
(friend)-[r:LIKED]->(place:Place),
(place)-[:IN_CATEGORY]->(c:Category)
WHERE alice.name = 'Alice' AND
c.name IN ['Fast Food', 'Desserts & Snacks'] AND
NOT (alice)-[:LIKED|CHECKED_INTO]->(place)
RETURN place.name AS place, AVG(r.score) AS avg_score
ORDER BY avg_score DESC
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Lab
========================================================
**Find all places that have received a score of 10 from any user. Return the place's name and the user's name.**
Lab
========================================================
**Find all places that have received a score of 10 from any user. Return the place's name and the user's name.**
```{r, echo=FALSE}
query =
"MATCH (u:User)-[r:LIKED]->(p:Place)
WHERE r.score = 10
RETURN u.name AS user, p.name AS place
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
options(digits=3)
printResult(query)
```
Dealing with Nonexistent Properties
========================================================
**Fast food places that Alice has either liked or checked into.**
```{r, echo=FALSE}
query =
"MATCH (alice:User)-[r:LIKED|CHECKED_INTO]->(place:Place),
(place)-[:IN_CATEGORY]->(c:Category)
WHERE alice.name = 'Alice' AND c.name = 'Fast Food'
RETURN place.name AS place, r.score AS score
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Dealing with Nonexistent Properties
========================================================
**Fast food places that Alice has either liked or checked into and the score she gave them.**
```{r, echo=FALSE}
query =
"MATCH (alice:User)-[r:LIKED|CHECKED_INTO]->(place:Place),
(place)-[:IN_CATEGORY]->(c:Category)
WHERE alice.name = 'Alice' AND c.name = 'Fast Food'
RETURN place.name AS place,
TYPE(r) AS action,
r.score AS score
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Paths
========================================================
**Who do Charles and David know each other through?**
```{r, echo=FALSE}
query =
"MATCH p = (a:User)-[:FRIENDS_WITH*]-(b:User)
WHERE a.name = 'Charles' AND b.name = 'David'
RETURN p
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
```{r, echo=FALSE}
testNonTabular(query)
```
Paths
========================================================
**Who do Charles and David know each other through?**
```{r, echo=FALSE}
query =
"MATCH p = (a:User)-[:FRIENDS_WITH*]-(b:User)
WHERE a.name = 'Charles' AND b.name = 'David'
RETURN LENGTH(p) AS path_length
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Paths
========================================================
**Who do Charles and David know each other through? Return the name property from all the nodes on the path.**
```{r, echo=FALSE}
query =
"MATCH p = (a:User)-[:FRIENDS_WITH*]-(b:User)
WHERE a.name = 'Charles' AND b.name = 'David'
RETURN EXTRACT(x IN NODES(p) | x.name) AS nodes,
LENGTH(p) AS path_length
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Paths
========================================================
**Who do Charles and David know each other through? Search for an exact path length of 3.**
```{r, echo=FALSE}
query =
"MATCH p = (a:User)-[:FRIENDS_WITH*3]-(b:User)
WHERE a.name = 'Charles' AND b.name = 'David'
RETURN EXTRACT(x IN NODES(p) | x.name) AS nodes,
LENGTH(p) AS path_length
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Paths
========================================================
**Who do Charles and David know each other through? Search for paths up to length-five.**
```{r, echo=FALSE}
query =
"MATCH p = (a:User)-[:FRIENDS_WITH*..5]-(b:User)
WHERE a.name = 'Charles' AND b.name = 'David'
RETURN EXTRACT(x IN NODES(p) | x.name) AS nodes,
LENGTH(p) AS path_length
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Collection Predicates
========================================================
**Who do Charles and David know each other through? Search for paths up to length-five. Forrest must be on the path.**
```{r, echo=FALSE}
query =
"MATCH p = (a:User)-[:FRIENDS_WITH*..5]-(b:User)
WHERE a.name = 'Charles' AND
b.name = 'David' AND
ANY(x IN NODES(p) WHERE x.name = 'Forrest')
RETURN EXTRACT(x IN NODES(p) | x.name) AS nodes,
LENGTH(p) AS path_length
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Collection Predicates
========================================================
**Who do Charles and David know each other through? Search for paths up to length-five. No one on the path can have liked Fly Bar.**
```{r, echo=FALSE}
query =
"MATCH p = (a:User)-[:FRIENDS_WITH*..5]-(b:User)
WHERE a.name = 'Charles' AND
b.name = 'David' AND
NONE(x IN NODES(p)
WHERE (x)-[:LIKED]->(:Place {name:'Fly Bar'})
)
RETURN EXTRACT(x IN NODES(p) | x.name) AS nodes,
LENGTH(p) AS path_length
"
```
### Query
```{r, echo=FALSE}
cat(query)
```
### Result
```{r, echo=FALSE}
printResult(query)
```
Shortest Path
========================================================
**What's the shortest path between Greta and Wendy's?**
```{r, echo=FALSE}
query =
"MATCH p = shortestPath((greta:User)-[*]-(wendy:Place))
WHERE greta.name = 'Greta' AND wendy.name = 'Wendy\\'s'
RETURN p
"