SDN4 Neo4j inheritance and index declaration at base class

106 Views Asked by At

This is my SDN 4 entities:

@NodeEntity
public abstract class BaseEntity {

    @Index(unique = false)
    private Date createDate;

....

}

@NodeEntity
public class Decision extends BaseEntity {  

....

}

This is :schema output:

Indexes
   ON :BaseEntity(createDate) ONLINE 

and I have a following Cypher query:

MATCH (d:Decision) WHERE d.createDate={createDate}

AFAIK (Neo4j SDN4 entity inheritance and indexes) this way Neo4j index :BaseEntity(createDate) will not be used because I'm trying to reach d node on :Decision label.

Is there any way at SDN 4 to define index via class inheritance(leave createDate at BaseEntity level) in order to be able to use createDate index on :Decision label ?

1

There are 1 best solutions below

0
On BEST ANSWER

If the query is a derived finder then it is related to this issue. The only way to work around this now is to use a custom @Query.

If the query is a custom @Query you just need to use the correct label in the query, note that you can use multiple labels:

MATCH (d:Decision:BaseNode) 
WHERE d.createDate={createDate}

The planner should be smart enough to do the right thing and use the index, nevertheless you should verify that using PROFILE. If not use the USING INDEX hint:

MATCH (d:Decision:BaseNode) 
USING INDEX d:BaseNode(createDate)
WHERE d.createDate={createDate}