Using a full-text Index on a Relationship Property

Step 1: Create the full-text index

Suppose we want to enable some Lucene-type queries against the role properties of the ACTED_IN relationships in our graph.

Create a full-text index on the ACTED_IN relationship using the role property. Name this index ACTED_IN_role_ft.

Step 2: Query the graph with the full-text index

After having added this full-text index, write a query to return the role properties of all ACTED_IN relationships that contain narrator and voice.

This query should return 67 rows.

Validate Results

Once you have completed the steps of this Challenge, click the Check Database button and we will check the database for you.

Hint

Index names, relationship type names, and property key names are all case-sensitive.

You can type SHOW INDEXES after you have created the index to confirm that it created the full-text indexes.

If you mess up, you can reload this Challenge page and you should be where you need to be at the beginning of this challenge.

Solution

Here are the statements to create the full-text index and query using the full-text index:

cypher
// Create the full-text index
CREATE FULLTEXT INDEX ACTED_IN_role_ft IF NOT EXISTS FOR ()-[x:ACTED_IN]-() ON EACH [x.role];

// query the graph with the full-text index
CALL db.index.fulltext.queryRelationships("ACTED_IN_role_ft", "+narrator +voice") YIELD relationship
RETURN relationship.role

Summary

In this Challenge, you demonstrated that you can create and use a full-text index for a relationship property. In the next module, you will learn more about using indexes in Neo4j.