Book Image

Neo4j Cookbook

By : Ankur goel, Ankur Goel
Book Image

Neo4j Cookbook

By: Ankur goel, Ankur Goel

Overview of this book

Table of Contents (17 chapters)
Neo4j Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

In this connected world, where gigabytes of unstructured information gets generated every second, the Neo4j graph database fits in perfectly to store such data and visualize it from every angle. A graph is the most natural form in which data can be stored and visualized, where every connected edge gives you a new path of the data flow and possible new insights into the data, which are not possible in the traditional data stores. Nearly, every company in a wide variety of domains, such as healthcare, retail, and travel, have realized the true potential of graph databases, and started to explore them for various use cases, such as recommendation, pattern detection, optimizing routes, and tons of other examples.

Many fortune 500 companies have adopted graph databases for a wide array of business-critical use cases and many start-ups are adopting them for new innovative use cases, which were never heard of before. Facebook, LinkedIn, and Twitter are the most well-known users of graph technologies for social web properties.

Neo4j, a graph database by Neo Technologies, is the leading player in the graph database market. It is so easy to use that even a non-technical person can easily browse the data and explore new use cases around it. With this also comes power-packed features that any enterprise database should have.

This cookbook not only provides insights into Neo4j but also into tools, libraries, and visualization tools in a short, concise manner, which will be required frequently when you are exploring Neo4j for a new case, deploying Neo4j to production, or scaling it to gigabytes of connected data. Regardless of whether you are a programmer, database expert, or data scientist, this book has recipes that can be easily learnt and applied.

What this book covers

Chapter 1, Getting Started with Neo4j, introduces Neo4j, and the installation of Neo4j on the operating system of your choice. It also helps you move your data from various formats, such as CSV, Geoff, or from other databases, such as RDBMS, OrientDB, and so on.

Chapter 2, Connecting to Neo4j, deals with the various ways in which you can connect to Neo4j with the programming language of your choice, such as Java, Python, Scala, and PHP, and also shows how you can access it over the REST interface, as well as using an embedded version of it.

Chapter 3, The Cypher Query Language, teaches you the most used aspect of Neo4j, which is Cypher. You will learn about queries, which you will need frequently when working with Neo4j.

Chapter 4, Data Modeling and Leveraging with Neo4j, explores the data modeling concepts and techniques associated with the graph data in Neo4j; in particular, the property graph model, design constraints for Neo4j, and modeling across multiple domains.

Chapter 5, Mining the Social Treasure, helps you build frequently used use cases around social data. Whether you use data from popular social networks, such as Facebook, LinkedIn, or have data of your own, this chapter quickly gets you started with social use cases.

Chapter 6, Developing Location-based Services with Neo4j, teaches you the most important aspect of today's data, location, and how to deal with it in Neo4j. You can also learn how to import geospatial data into Neo4j and run queries, such as proximity searches, bounding boxes, and so on.

Chapter 7, Visualization of Graphs, shows you how to integrate the Neo4j graph database with the powerful domain of graph visualizations. We will discuss the different alternatives and resources to get started with.

Chapter 8, Industry Usages of Neo4j, shows you how different industries, such as healthcare, travel, and retail, use Neo4j in their domains. This all comes with a sample dataset and queries, which you can easily build and execute to see it running.

Chapter 9, Neo4j Administration and Maintenance, deals with recipes for deploying Neo4j on different clouds, backup strategies, debugging and security aspects.

Chapter 10, Scaling Neo4j, teaches you how to develop applications with Neo4j to handle high volumes of data. You will learn about different aspects while scaling different types of applications over Neo4j.

What you need for this book

This book is intended for users who work on machines based on Linux, Mac OS X, or Windows. All the prerequisites are described in the first and second chapters, to make sure that your system is Neo4j-enabled and meets a few requirements. In general, all the examples should work on any platform.

This book assumes that you have a basic understanding of graph theory and are familiar with the fundamental concepts of Neo4j. It focuses primarily on recipes around Neo4j, which are required frequently.

A reasonable and recommended lab setup can be done on a machine with a dual or quad-core processor with 8 GB (Gigabyte) of RAM. A system with a less powerful configuration would probably also work, but the recommended one will make it more comfortable for you.

You might be required to install libraries or tools, depending on the recipe you are executing, which have been explained in the recipe itself.

Who this book is for

If you are already using Neo4j in your application and want to learn more about data analysis or database graphs, this is the book for you. This book also caters for your needs if you are looking to migrate your existing application to Neo4j in the future. We assume that you are already familiar with any general purpose programming language and have some familiarity with Neo4j.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, shell commands, file extensions, pathnames, dummy URLs, user input are shown as follows: "A good approach for this recipe will be to go through the readme file, which is present in the top level directory, and follow the steps given in that file".

A block of code is set as follows:

Node node = embed.createNode();
node.setProperty("name","Neo4j");
node.setProperty("Message","Hello World");

The shell commands are provided in the following manner

$ curl -H Accept:application/json -H Content-Type:application/json  http://localhost:7474/db/data/node/2/relationships/all

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "We can see two nodes, 2 and 3, in the data visualization, which are connected to each other."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of. To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/7253OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.