Search code examples
neo4jcyphergraph-databasesmemgraphdbopencypher

Querying nodes using array property - neo4j


I have a property on the node which is stored as array of strings. But when I use this field to find the node, it's not returning any results. What am I doing wrong?

Below is the node:

MATCH (n:Product)
WHERE
n.id_product = 8
RETURN
n.keyterms

Result

["financial tool", "personal finance"]

I am trying to find the same node as above using the keyterms field:

MATCH (n:Product)
WHERE
["financial tool"] in n.keyterms
RETURN
n.keyterms

no records

Solution

  • You don't have to put "financial tool", in an array, simply try this:

    MATCH (n:Product)
    WHERE "financial tool" in n.keyterms
    RETURN n.keyterms
    

    To search for, multiple values, you can do the following:

    MATCH (n:Product)
    WHERE ANY (key IN n.keyterms WHERE key IN ['financial tool', 'personal finance'] )
    RETURN n.keyterms