· javascript neo4j neo4j-browser

Neo4j Browser: Expected entity id to be an integral value

I came across an interesting error while writing a Cypher query that used parameters in the Neo4j browser which I thought I should document for future me.

We’ll start with a graph that has 1,000 people:

unwind range(0,1000) AS id
create (:Person {id: id})

Now we’ll try and retrieve some of those people via a parameter lookup:

:param ids: [0]
match (p:Person) where p.id in {ids}
return p

╒════════╕
│"p"     │
╞════════╡
│{"id":0}│
└────────┘

All good so far. Now what about if we try and look them up by their internal node id instead:

match (p:Person) where id(p) in {ids}
return p

Neo.ClientError.Statement.TypeError
Expected entity id to be an integral value

Hmm, that was unexpected. It turns out that to get this query to work we need to cast each of the integer values in the {ids} array to a 64 bit integer using the https://neo4j.com/docs/developer-manual/current/cypher/functions/scalar/#functions-tointeger function:

match (p:Person) where id(p) in [id in {ids} | toInteger(id)]
return p

╒════════╕
│"p"     │
╞════════╡
│{"id":0}│
└────────┘

Success!

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket