I would recommend changing your Schema to something like: [image: image.png]
Because it will reduce *number of relationships *between Piece nodes from *n^2 to n*. And your query can then be something like: MATCH (Paiting_1:Piece)-[:IN_HALL]->(Common_hall:Hall)<-[:IN_HALL]-(Paiting_2:Piece) MATCH (Red_1:Color) MATCH (Blue_1:Color) WHERE Red_1.name CONTAINS 'Cherry' AND Blue_1.name CONTAINS 'Sea' AND NOT Paiting_1.name CONTAINS Paiting_2.name AND (Red_1)-[:IS_IN]->(Paiting_1) AND (Blue_1)-[:IS_IN]->(Paiting_2) RETURN Paiting_1.name, Paiting_2.name *Please share if there is a decrease in time by doing above and also after try changing the order of conditions like:* MATCH (Paiting_1:Piece) MATCH (Red_1:Color) MATCH (Paiting_2:Piece) MATCH (Blue_1:Color) WHERE Red_1.name CONTAINS 'Cherry' AND Blue_1.name CONTAINS 'Sea' AND NOT Paiting_1.name CONTAINS Paiting_2.name AND (Paiting_1)-[:IN_SAME_HALL]->(Paiting_2) AND (Red_1)-[:IS_IN]->(Paiting_1) AND (Blue_1)-[:IS_IN]->(Paiting_2) RETURN Paiting_1.name, Paiting_2.name *Thanks & Regards* *Lalit Kumar Singh | Software Developer* On Thu, Jan 31, 2019 at 5:39 AM Ismael Rodríguez Brena < ismarodrigue...@gmail.com> wrote: > Hi everybody, > > I am complete beginner with Neo4j and I am trying to do an script which > find patterns (particular subgraphs) in the Database. > My query looks something like this: > > MATCH (Paiting_1:Piece) > MATCH (Red_1:Color) > MATCH (Paiting_2:Piece) > MATCH (Blue_1:Color) > WHERE Red_1.name CONTAINS 'Cherry' > AND Blue_1.name CONTAINS 'Sea' > AND NOT Paiting_1.name CONTAINS Paiting_2.name > AND (Red_1)-[:IS_IN]->(Paiting_1) > AND (Blue_1)-[:IS_IN]->(Paiting_2) > AND (Paiting_1)-[:IN_SAME_HALL]->(Paiting_2) > RETURN Paiting_1.name, > Paiting_2.name > > This query gets me the expected result, but as soon the size of the > subgraphs I am looking grows, the times need to answer the query increases > exponentially. > Probably there is a more fancy and efficient way to do it, but I haven't > found it yet. > > Best, > Ismael > > -- > You received this message because you are subscribed to the Google Groups > "Neo4j" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to neo4j+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- IMPORTANT: NEVER share your IndiaMART OTP/ Password with anyone. -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.