cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How do I match substrings using Cypher other than CONTAINS keyword?

2X_3_3131145607ee4c9cb1fe2e4a3053b2258ed9f24a.png
2X_e_ed40a21db25488f8fe54f06bd148b1034a27077a.png
Here are the two datasets named books and genres both having columns Genre.
I want to create a relationship where books will be mapped to their respective genres(Please note: Each book has multiple genres)
The following code was run :
MATCH(B:Books),(G:Genres)
WHERE B.Genres CONTAINS G.Genres
CREATE (B)-[r:BelongsTo]->(G) RETURN type(r)

And the result obtained was :
2X_c_c764ce82956f84306f4fe96f6ac3825ea42cf081.png

By executing the above query, only the books belonging to Fiction Genre were mapped , but the other books belonging to the other categories were not mapped. Someone help please

2 REPLIES 2

Jiropole
Graph Voyager

It's hard to tell what design you want to achieve.

I wonder if you're just looking for a design that lets you run

MATCH (b:Book)-[:HAS_GENRE]->[g:Genre]

That's fine, so long as you've designed your data to be ready for this question. Perhaps you can provide more info on your end goals.

You may want to review your :Genre nodes and ensure there are no leading or trailing spaces, as that could be a reason why your matching isn't working as expected.

On a :Book node, is Genres a list property, or is it one large string? Is there a reason why you're wanting to use substring matching instead of equality, for each genre in the list?