I want to store some nodes which have integers, how do i make neo4j understand that the characters i am sending are integers.
I tried
MATCH (a:Venture_capital),(b:Organization)
WHERE a.name = "Google" AND int(b.from) = "2004" AND String(b.member) = "John L. Hennessy"
CREATE (a)-[:board_members]->(b)-[:organization]->(a)
and
MATCH (a:Venture_capital),(b:Organization)
WHERE a.name = "Google" AND b.from = int("2004") AND b.member = String("John L. Hennessy")
CREATE (a)-[:board_members]->(b)-[:organization]->(a)
Both are not working. :(
How am i supposed to do that?
Neo4j does not allow me to store datetime and spatial data by default that's weird.
Try:
toFloat(5)
This is a workaround, more details see "Provide a way to set properties with Integer (not Long) values in Cypher #7652" on github.
Use toInt(string)
MATCH (a:Venture_capital),(b:Organization)
WHERE a.name = "Google" AND b.from = toInt("2004")
AND b.member = "John L. Hennessy"
CREATE (a)-[:board_members]->(b)-[:organization]->(a)
Related
This seems like a simple use case but I'm having trouble locating an example in the docs.
I want to do the following:
MERGE(node:Graph{id:{id}})
ON CREATE SET node.firstseen = timestamp(),
SET node.id = {id},
node.list = [list]
Examples of this would be appreciated, thanks!
You have a comma before your SET clause:
ON CREATE SET node.firstseen = timestamp(),
^
The correct query is
MERGE (node:Graph {id:$id})
ON CREATE SET node.firstseen = timestamp()
SET
node.list = $list
You don't need to set the id field, the MERGE takes care of this. The list field will be set every time you call the query, the firstseen timestamp only when the node doesn't exist.
Assuming you pass id and list as parameters:
MERGE (node:Graph {id: $id})
ON CREATE SET
node.firstseen = timestamp(),
node.list = $list
You cannot have a SET clause within another SET clause. Besides, it is unnecessary to SET node.id = $id anyway, since your MERGE already guarantees that property has that value.
I have this Cypher query and I can't figure out how to take advantage of a composite index when running it. I tried an index on type, for, buying and renting properties on both nodes, but the index doesn't show up on query's PROFILE.
MATCH (prof:Profile)
MATCH (prop:Property)
WHERE prof.type = prop.type
and prof.for = prop.for
and prof.buying = prop.buying
and prof.renting = prop.renting
Is it even possible to achieve this?
This will do the trick (for the second node type) :
PROFILE MATCH (pp:Property)
WITH pp, pp.type as type, pp.for as for, pp.bying as buying, pp.renting as renting
MATCH (pf:Profile)
WHERE pf.type = type
AND pf.for = for
AND pf.buying = buying
AND pf.renting = renting
RETURN pp, pf;
The reason the index is not used is that it has no actual values to use it with, those are only available after the nodes have been scanned.
Hope this helps.
Regards,
Tom
I'm currently running the following query to update the properties on two nodes and relationships.
I'd like to be able to update 1,000 nodes and the corresponding relationships in one query.
MATCH (p1:Person)-[r1:OWNS_CAR]->(c1:Car) WHERE id(r1) = 3018
MATCH (p2:Person)-[r2:OWNS_CAR]->(c2:Car) WHERE id(r2) = 3019
SET c1.serial_number = 'SERIAL027436', c1.signature = 'SIGNATURE728934',
r1.serial_number = 'SERIAL78765', r1.signature = 'SIGNATURE749532',
c2.serial_number = 'SERIAL027436', c2.signature = 'SIGNATURE728934',
r2.serial_number = 'SERIAL78765', r2.signature = 'SIGNATURE749532'
This query has issues when you run it in larger quantities. Is there a better way?
Thank you.
You could work with a LOAD CSV. Your input would contain the keys (not the ids, using the ids is not recommended) for Person and Car and whatever properties you need to set. For example
personId, carId, serial_number, signature
00001, 00045, SERIAL78765, SIGNATURE728934
00002, 00046, SERIAL78665, SIGNATURE724934
Your query would then be something like :
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///input.csv' AS row
MATCH (p:Person {personId: row.PersonId})-[r:OWNS_CAR]->(c:Car {carId: row.carId})
SET r.serial_number = row.serialnumber, c.signature = row.signature
Note that you should have unique constraints on Person and Car to make that work. You can do thousands (even millions) like that very quickly ...
Hope this helps,
Tom
I have an object which has a unique but not required property, i.e. a Facebook ID. If I insert another of the object with the same name and there is an object without a Facebook ID then I assume they are the same. If there is an object with the same name but a different Facebook ID then I assume they're different and create a new object.
I've tried various statements based off the Cypher documentation but couldn't get any of them to be valid syntax.
While this example is not valid I think it gets the point across of what I'm trying to do:
MERGE (t:Thing {name: 'My Not Always Unique Name'})
WHERE EXISTS(t.facebook_id) AND t.facebook_id <> '111111111'
ON CREATE SET t.name = 'My Not Always Unique Name',
t.facebook_id = '111111111',
t.another_property = 'blah'
ON MATCH SET t.another_property = 'blah'
RETURN t;
I believe I have an answer for this which depends on the UUIDs that I'm setting to the id property.
OPTIONAL MATCH (t:Thing {name: 'My Not Always Unique Name'}) WHERE t.facebook_id IS NULL OR t.facebook_id = '1111111'
WITH t
MERGE (s:Thing {id: COALESCE(t.id, 'e8344f24-faff-443a-ac48-b757381eddb8')})
ON MATCH SET s.name = 'My Not Always Unique Name', s.facebook_id = '1111111'
ON CREATE SET s.name = 'My Not Always Unique Name', s.facebook_id = '1111111' RETURN s;
Not sure if this is the best way to do this but it works for me. I'll leave this open for a little to see if anyone has a better answer.
One negative side-effect is if I'm inserting something that doesn't have a facebook_id it will need a separate merge statement.
I need to create a relation between two users once, and update its properties since then. Is there a way to do something like "create if not exist otherwise update" in Neo4j using Cypher?
MERGE (u1:User)-[r:REL]->(u2:User)
ON CREATE SET
u1.prop1 = val1,
u2.prop2 = val2,
r.prop3 = val3
ON MATCH SET
u1.prop1 = newVal1,
u2.prop2 = newVal2,
r.prop3 = newVal3
Have a look at the Neo4j docs for "MERGE".