Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-01-2021 07:32 PM
I create a index on relationship
CREATE LOOKUP INDEX rel_type_lookup_index FOR ()-[r]-() ON EACH type(r)
But this can't hit the relationship index
explain match (p:Person)-[r]->(m:Movie) where type(r) ='Knows' return p ;
How should I create an index?
Solved! Go to Solution.
07-05-2021 01:51 AM
I don't know where you did get this kind of model from, I definitely recommend to you to adjust your model to the recommended form otherwise you're fighting the system and won't be happy 🙂
Usually graph models are like this (Subject Predicate Object) on the schema-level:
(:Person)-[:WROTE|READ]->(:Book)
So they form a fact, which you then can query by the start- and end-labels and rel-types.
e.g.
MATCH (p:Person)-[:WROTE|READ]->(b:Book)
RETURN p, b
or
MATCH (p:Person)
WHERE exists { (p)-[:WROTE|READ]->(:Book) }
RETURN p
07-02-2021 03:29 PM
it only works when you use the literal rel-types
explain match (p:Person)-[r:Knows]->(m:Movie) return p ;
07-02-2021 08:11 PM
But how to get this hit to the relationship index? How should I create an index?I don't know the specific type of edge.
explain match (p:Person)-[r]->(m:Movie) where type(r) ends with 'nows' return p ;
07-03-2021 01:24 AM
The index is only per type. Not generally for all rels.
What does your data model look like?
07-04-2021 05:27 AM
A person
has many relationships, and I created different names for these relationships. For example, person-[person_read_book]-book
, person-[person_write_book]-book
, I want to find out who read or wrote a book, person-[r]-[book] type(r) ends with book
.
07-04-2021 05:28 AM
So I want to create index for relationships.
07-04-2021 01:13 PM
Why not instead check the label on the other node.
Where other:Book
07-04-2021 07:29 PM
Sorry, let me re-describe the scene. reader-[reader_read_book]-book
, writer-[writer_write_book]-book
, I want to know who has read or written a certain book, there are many different types, I don’t know which node types are there , I only know book. So I query (n)-[r]-(b:Book) where type(r) ends with 'book' return n
07-05-2021 01:51 AM
I don't know where you did get this kind of model from, I definitely recommend to you to adjust your model to the recommended form otherwise you're fighting the system and won't be happy 🙂
Usually graph models are like this (Subject Predicate Object) on the schema-level:
(:Person)-[:WROTE|READ]->(:Book)
So they form a fact, which you then can query by the start- and end-labels and rel-types.
e.g.
MATCH (p:Person)-[:WROTE|READ]->(b:Book)
RETURN p, b
or
MATCH (p:Person)
WHERE exists { (p)-[:WROTE|READ]->(:Book) }
RETURN p
07-05-2021 02:25 AM
What you said makes sense, and thank you very much for your reply.
All the sessions of the conference are now available online