Search code examples
neo4jcypher

How can I make a string contain filter on Neo4j Cypher


I need to create a string containment filter in Neo4j.

For example, I want to retrieve all people from a database whose names contain the substring "car".

How can I do this?


Solution

  • You can use regular expressions to match a part of a name, for example:

    MATCH (n)
    WHERE n.name =~ '.*car.*'
    RETURN n
    

    If you have the label 'Person' assigned to all people in your database, the query would be:

    MATCH (n:Person)
    WHERE n.name =~ '.*car.*'
    RETURN n
    

    For further information, see http://docs.neo4j.org/chunked/stable/query-where.html#_regular_expressions