Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-25-2019 03:52 AM
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?
01-25-2019 05:02 AM
Sorry. It took time to build index. That's why it wasn't worked. The index works now.
01-25-2019 05:02 AM
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
06-30-2021 12:09 PM
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 ?
06-30-2021 12:51 PM
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.
06-30-2021 01:41 PM
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.
All the sessions of the conference are now available online