cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

When to use labels and relation types indexing from Neo4j 4.3?

Hi all,

In NODES 2021, label and type indices, available from the 4.3 server, were presented. However, I haven't clear when I should or should not use this kind of indices.

Naively, I tend to think that in most cases, there will be searches like MATCH ( n: ) - [r:] -> (...) so, I'd say it's good to have them in most cases.

But maybe I'm wrong? Maybe they benefit more certain types of queries only?

Thanks in advance for your answer.

3 REPLIES 3

Regarding relationship type index see The use of indexes - Neo4j Cypher Manual

and to which if you have properties defined in the relationship itself and provided said index exists then running

match (n)-[r:FOLLOWS]->() where r.<property>=<value> return n;

then the index will be used. Where might this be helpful? If for example a node has 20000 :FOLLOWS relationships and each relationship is has a property named status and for example most relationships (i.e. > 95%) have a status of active. If I run

match (n)-[r:FOLLOWS]->() where r.status='inactive' return n;

then the index will be used and rather that interating over all 20k relationships the index will allow us to only iterate over the < 5% of :FOLLOWS relationships for the given node

Many thanks, @dana.canzano, now it's clearer.

Regarding the label/relation-type level indices, I infer that they can be useful when expressions involving entity types appear on the WHERE clause and select a subset of entities.

@marco.brandizi correct. Without a WHERE clause and restriction on said indexed property the index will not be utiilzied.

A simple

match (n)-[r:FOLLOWS]->()  return n;

would not use the index (provided it existed)