Learning Cypher Write powerful and efficient queries for Neo4j with Cypher, its official query language Onofrio Panzarino BIRMINGHAM - MUMBAI Learning Cypher Copyright 2014 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information. First published: May 2014 Production Reference: 1070514 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78328-775-8 www.packtpub.com Cover Image by Jaroslaw Blaminsky (milak6@wp.pl) Credits AuthorCopy Editors Onofrio Panzarino Mradula Hegde Gladson Monteiro Reviewers Riccardo Mancinelli Project Coordinator Rohit Mukherjee Harshal Ved Timmy Storms Craig Taverner Proofreader Ameesha Green Commissioning Editor Antony Lowe Indexer Mariammal Chettiyar Acquisition Editor Owen Roberts Graphics Yuvraj Mannari Content Development Editor Abhinash Sahu Priyanka S Production CoordinatorTechnical Editors Aparna Bhagat Taabish Khan Nikhil Potdukhe Cover Work Aparna Bhagat Akash Rajiv Sharma About the Author Onofrio Panzarino is a programmer with 15 years experience working with various languages (mostly with Java), platforms, and technologies. Before obtaining his Master of Science degree in Electronics Engineering, he worked as a digital signal processor programmer. Around the same time, he started working as a C++ developer for embedded systems and PCs.
Currently, he is working with Android, ASP.NET or C#, and JavaScript for Wolters Kluwer Italia. During these years, he gained a lot of experience with graph databases, particularly with Neo4j. Onofrio resides in Ancona, Italy. His Twitter handle is (@onof80). He is a speaker in the local Java user group and also a technical writer, mostly for Scala and NoSQL. In his spare time, he loves playing the piano with his family and programming with functional languages.
First and foremost, I would like to thank my wife, Claudia, and my son, Federico, who patiently supported me at all times. Special thanks to the team at Packt Publishing. It has been a great experience to work with all of you. The work of all the reviewers was invaluable as well. I would also like to thank all my friends who read my drafts and gave me useful suggestions. About the Reviewers Riccardo Mancinelli has acquired a degree in Electronics Engineering.
He has more than nine years of experience in IT, specializing in frontend and backend software development. He currently works as an IT architect consultant and a senior Java developer. He loves any tool and programming language that will help him achieve his goal easily and quickly. Besides programming, his favorite hobby is reading. Rohit Mukherjee is a student of computer engineering at the National University of Singapore (NUS). He is passionate about software engineering and new technologies.
He is currently based in Zurich, Switzerland, on a student exchange program at ETH, Zurich. Rohit has worked for Ernst and Young in Kolkata, Bank of America Merrill Lynch in Singapore, and Klinify in Singapore. He was a technical reviewer for Google Apps Script for Beginners, Serge Gabet, Packt Publishing. I would like to thank my parents for their support. Timmy Storms started working as a Java consultant after he completed his Bachelor's degree in Information Technology. He acquired SCJP, SCWCD, and SCBCD certifications to boost his overall Java knowledge.
Over the years, he has worked in several industries, such as banking, and health care as well as for the government, where he gained a broad overview of the Java landscape. In the initial years of his career, he worked mostly as a frontend developer, but later on shifted his focus to backend technology. He discovered the wonderful world of graph databases, and especially Neo4j, in late 2012. After he developed a social platform, he quickly saw the benefits of Neo4j and its query language Cypher. Being an early adopter of modules such as Spring Data Neo4j and cypher-dsl, he has made some contributions to the source code as well. Learning Cypher is the first book that he has reviewed, and he doesn't expect it to be his last one. Craig Taverner is an open source software developer, technology enthusiast, and entrepreneur working on many projects, especially those that involve Ruby, GIS, and Neo4j. Craig Taverner is an open source software developer, technology enthusiast, and entrepreneur working on many projects, especially those that involve Ruby, GIS, and Neo4j.
He is the CTO and co-founder of AmanziTel AB, where he helps build really cool telecom statistics platforms. Having a background in pure science, Craig has spent the last two decades working mostly in the mobile telecom field, where he has applied his analytical skills to help large international operators solve their complex data analysis problems. During this time, he has also contributed to several open source projects, most notably Neo4j Spatial, as well as presented at many conferences, such as FOSS4G 2010 and 2011 and GraphConnect 2012 and 2013. In addition, he has reviewed several technical books, including Domain Specific Languages, Martin Fowler, Addison-Wesley Professional; Linked Data, David Wood and Marsha Zaidman, Manning Publications; and Neo4j inAction, Jonas Partner, Aleksa Vukotic, and Nicki Watt, Manning Publications. www.PacktPub.com Support files, eBooks, discount offers, and more You might want to visit www.PacktPub.com for support files and downloads related to your book. com and as a print book customer, you are entitled to a discount on the eBook copy. com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Table of Contents Table of Contents[ ii ]Table of Contents[ iii ]Table of Contents[ iv ] Preface Among the NoSQL databases, Neo4j is generating a lot of interest due to the following set of features: performance and scalability, robustness, its very natural and expressive graph model, and ACID transactions with rollbacks. Neo4j is a graph database. Its model is simple and based on nodes and relationships. The model is described as follows: Each node can have a number of relationships with other nodes Each relationship goes from one node either to another node or the same node; therefore, it has a direction and involves either only two nodes or only one Both nodes and relationships can have properties, and each property has a name and a value Before Neo4j introduced Cypher as a preferred query, utilizing Neo4j in a real-world project was difficult compared to a traditional relational database. In particular, querying the database was a nightmare, and executing a complex query required the user to write an object, thereby performing a graph traversal. Roughly speaking, a traversal is an operation that specifies how to traverse a graph and what to do with the nodes and relationships found during the visit.
Next page