cancel
Showing results for 
Search instead for 
Did you mean: 

Index on array

noff
Node

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?

5 REPLIES 5

noff
Node

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

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

is it still valid recommendation with the latest version of Neo4j 4.3? Should I use the connected nodes instead of the indexed array-property ?

I don't believe there's been a change here yet. There is active work going on with index changes, but nothing to report on support for indexed elements of list properties.

Thanks for your answer. Right now I'm trying to design RBAC for my Neo4j application so will try to think how to properly implement it with the role/permission nodes.