Use index on LABEL (not properties)

neo4j-shell
index
(Jotapdiez) #1

Hi all!

I have a database with 34 labels and i'm using that labels to add properties based on groups.

i.e:

MATCH (x:FST) set x:GRPONE;
MATCH (x:SND) set x:GRPONE;
...
MATCH (x:TRD) set x:GRPTWO;
...
MATCH (x:FRD) set x:GRPTHREE;
...

MATCH (x:GRPONE)-[*]->(:GROUPTWO)<--(:GRPTHREE) SET x.importantPropertie=1;

(the match to set properties sometimes involves counting other properties, relation properties, and more)

Is there any way to create index based on labels (and not properties) to prevent NodeByLabel on matches?

I'm trying another version of my script using a property instead of labels but I can't create (and remove) an index on ALL labels. Is that possible?

Thanks in advance
Regards Juan Pablo

0 Likes

(Andrew Bowman) #2

I'm not entirely clear on what you're asking.

Indexes are based on label + property, you need both.

And if you want to look up a node by its label and you don't have a property to use for lookup, then it will do a NodeByLabelScan, looking at all nodes for the given label, there's literally no better option, it's literally an index based on labels as you requested.

0 Likes

(Jotapdiez) #3

That's exactly what I was asking.

Thanks for the answer and sorry about my English.

0 Likes