Chapter 2. Querying and Indexing in Neo4j

From what we learned in the previous chapter, we can say that while a relational database can be used to obtain the average age of all the people in a room, a graph database can indicate who is most likely to buy a drink. So, the utility of graph databases in the information age is vital.

In this chapter, we are going to take a look at the querying and indexing features of Neo4j and focus on the following areas:

  • The Neo4j web interface
  • Cypher queries and their optimization
  • Introduction to Gremlin
  • Indexing in Neo4j
  • Migration techniques for SQL users

The Neo4j interface

Neo4j comes with a browser-based web interface with the ability to manage your database, run queries in Cypher or REST, as well as visualization support for graphs. You can view the status of your database with a node and the relationship count and disk usage stats under dashboard. The data browser helps you to run queries and visualize the results in the form of a graph. You can use the console option to run queries on the database. Cypher and REST are supported in the console of the web interface. Gremlin support was deprecated in the recent version but you can always use it as a powerful external tool. Overall, the web interface provides developers with an easy-to-use system with a frontend for monitoring and querying.

Running Cypher queries

The default page when you open Neo4j is http://localhost:7474/browser/, and it is an interactive shell in the browser to execute your queries in a single or multiline format. You can also view the results locally in the timeline format along with tables or visualizations depending upon the query. Queries can be saved using the star button in the pane and the current content in the editor will be saved. Drag and drop of scripts for stored queries or data import is also possible in this interface.

Running Cypher queries

For administrative purposes, you can redirect to the webadmin interface at http://localhost:7474/webadmin/, which houses several features and functions that can be used to manage and monitor your database system.

Running Cypher queries

The Neo4j webadmin interface

Visualization of results

The most fascinating way of interacting with graphs is visualization. When you run Cypher queries, the result set is generally made up of nodes and relationships that are viewed in the data browser. Clicking on a node or a relationship in the visualizations will show a popup that contains the properties of that entity.

Visualization of results

Visualization of results

You can also customize the content and colors, based on the label or type of relationship. A label is a named graph construct that is used to group nodes or relationships into sets; all nodes labeled with the same label belong to the same set. A type refers to different types of relationships that are present in the graph. (This is different from __type__, which is a property in Spring Data Neo4j used to map objects to nodes/relationships.) The elegance and design of Neo4j comes from the fact that every interaction that we have with it is a demonstration. It not only has a fluid and interactive UI but also a high-end administrative functionality.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset