Index on array

cypher
index

(Noff) #1

Hello.
I'm trying to implement search of nodes by its' array property.
I have 11M nodes.
10-100 of nodes have tags field (array or null).

Like:

MATCH (n:address {name: '...'}) SET n.tags = ['test1', 'test2'] RETURN n;

I've added index:

CREATE INDEX on :address(tags);

When I perform a search:

MATCH (n:address) WHERE n.tags IN ['test1'] RETURN n;

it takes 10 minutes to make an operation. Looks like it doesn't use the index. Explain shows:

NodeByLabelScan => 11M estimated rows
Filter => n tags in $' AUTOLIST0' => 10M estimated rows.

Can you help to figure out why the index doesn't apply?


(Noff) #2

Sorry. It took time to build index. That's why it wasn't worked. The index works now.


(Andrew Bowman) #3

If you review the using indexes section of the documentation, you'll see that this use case isn't supported.

For cases like these, where you have nodes with a list property (such as tags as in your case) where you need to lookup the node by one of its list values, we recommend modeling the tags as separate connected nodes (such as (:Tag{name:'test1'}), create an index on this, then match to the pattern:

MATCH (n:Address)-[:TAG]->(t:Tag)
WHERE t.name in ['test1']
RETURN n