Reputation: 79
I am trying to write a query that has a filter which includes some properties whose values are bigger than 0, and includes certain nodes where the difference between two properties is bigger than 0. However, with Neo4j v 2.1.6.
This is query is run in a java program through the embedded Neo4j engine.
My query looks something like this:
MATCH (fromJar)-[:IN]->(c)<-[:IN]-(toJar) WHERE c.status='ToDo' AND fromJar.content > 0 AND (toJar.volume - toJar.content) >0 RETURN ID(c) AS contextID, c.step, fromJar.name, fromJar.volume, fromJar.content, toJar.name, toJar.volume, toJar.content
However, I am getting the following error:
Exception in thread "main" org.neo4j.cypher.CypherTypeException: Don't know how to Subtract(Property(NodeIdentifier(),volume(8),Property(NodeIdentifier(),content(9))) `0` with `5`
Any ideas as to what is causing this? Or a how to work around it?
Upvotes: 0
Views: 626
Reputation: 66999
AS @DaveBennet suggested, you are probably setting your volume
and content
properties to string values. If you are, then this should "fix" your problem (also, note that the last term in the WHERE
clause is simplified):
MATCH (fromJar)-[:IN]->(c)<-[:IN]-(toJar)
WHERE c.status='ToDo' AND TOINT(fromJar.content) > 0 AND
(TOINT(toJar.volume) > TOINT(toJar.content))
RETURN ID(c) AS contextID, c.step, fromJar.name, fromJar.volume,
fromJar.content, toJar.name, toJar.volume, toJar.content;
However, the above fix is not very performant, as it is constantly performing (what should really be unnecessary) type conversions. It would be better if you changed those properties so that they have numeric values. If you do, then then the query will look like this:
MATCH (fromJar)-[:IN]->(c)<-[:IN]-(toJar)
WHERE c.status='ToDo' AND fromJar.content > 0 AND (toJar.volume > toJar.content)
RETURN ID(c) AS contextID, c.step, fromJar.name, fromJar.volume,
fromJar.content, toJar.name, toJar.volume, toJar.content;
And, to further improve performance, the c
node in your query should be labeled, and there should be an index for that label and the status
property.
Upvotes: 3