Step 1: Create TEXT index
Create a TEXT index on the ACTED_IN relationship using the role property. Name this index ACTED_IN_role_text.
Step 2: Query the graph without specifying any query hints
Execute this query:
PROFILE MATCH
(p:Person)-[r:ACTED_IN]->(m:Movie)
WHERE
p.name CONTAINS 'George'
AND
r.role CONTAINS 'General'
RETURN p.name, r.role, m.title
This query should return 2 rows. What index does it use?
Modify the query to use the ACTED_IN_role_text index as a query hint.
Does it use the correct index?
Is the performance better?
In this case you will see that the elapsed time using either query is about the same, but there are fewer db hits with the use of the TEXT index on the relationship property.
Validate Results
Once you have completed the steps of this Challenge, click the Check Indexes 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 TEXT index and query using the query hints:
// Create the TEXT index on the role property of the ACTED_IN relationship
CREATE TEXT INDEX ACTED_IN_role_text IF NOT EXISTS FOR ()-[x:ACTED_IN]-() ON (x.role);
// query the graph with the query hint to use the newly-created indes
PROFILE MATCH
(p:Person)-[r:ACTED_IN]->(m:Movie)
USING INDEX r:ACTED_IN(role)
WHERE
p.name CONTAINS 'George'
AND
r.role CONTAINS 'General'
RETURN p.name, r.role, m.title
Summary
In this Challenge, you demonstrated that you can specify a query hint for an index on a relationship. In the next lesson, you will learn how important index best practices must be followed.