Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-06-2021 01:19 PM
We have a lable on each node in the database containing a description (e.g. lable:"contains a pond, a shed, and several large trees") and we need to search the database for any node whos label contains ["pond", "tree", "snake"]
So we want the node if its label contains any of those 3 words. I would prefer a list to just a series of ANDS
Solved! Go to Solution.
02-09-2021 11:02 PM
This is faster:
EXPLAIN MATCH(n)
WHERE n:Label3 OR n:Label5 return n
The EXPLAIN
shows that there's an MATCH n:Label3
and then MATCH n:Label5
followed by a UNION of these two small sets.
whereas the MATCH (n)
does a match for every node in the DB, which is very expensive.
The another consideration, is if you have a node with two labels
create (n:Label3:Label5);
my solution will count this as one node.
02-06-2021 02:23 PM
i think this is what you want
:use system
create database multiLabel;
:use multiLabel
create (n:Label1);
create (n:Label2);
create (n:Label3);
create (n:Label4);
create (n:Label5);
create (n:Label6);
match (n) unwind labels(n) as oneLbl
with n,oneLbl where oneLbl in ['Label3','Label5'] return n;
to which this results in output of
+-----------+
| n |
+-----------+
| (:Label3) |
| (:Label5) |
+-----------+
note this might be an expensive operation since we are examining all nodes in the database to see if they contain one of the labels
02-06-2021 02:28 PM
Thank you - I'll try it as soon as the DB comes back up.
02-07-2021 07:03 PM
Worked perfectly and as you expected, slowly. But it has all night to run. Thanks
02-09-2021 11:49 PM
match (n)
where labels(n) in [['Label3'],['Label5']] return n;
02-10-2021 05:48 PM
Some interesting solutions. I'll try those. Thank you
02-09-2021 11:02 PM
This is faster:
EXPLAIN MATCH(n)
WHERE n:Label3 OR n:Label5 return n
The EXPLAIN
shows that there's an MATCH n:Label3
and then MATCH n:Label5
followed by a UNION of these two small sets.
whereas the MATCH (n)
does a match for every node in the DB, which is very expensive.
The another consideration, is if you have a node with two labels
create (n:Label3:Label5);
my solution will count this as one node.
All the sessions of the conference are now available online