I am not sure how to use mergeE and mergeV using gremlin_python

I am using janusgraph with cassandra for my project and I want to implement upsert functionality. For that I didn't find much resources, only this gist (https://gist.github.com/spmallette/5cd448f38d5dae832c67d890b576df31) . From that, I wrote certain code which does work. The code looks like this
For vertex/node
g.merge_v({T.id: node.id}).option(
Merge.on_create, {
T.label: node.type.value,
'name': node.name
}
).option(
Merge.on_match, {
'name': node.name
}
).property("full_name": node.full_name) \
.next()
For vertex/node
g.merge_v({T.id: node.id}).option(
Merge.on_create, {
T.label: node.type.value,
'name': node.name
}
).option(
Merge.on_match, {
'name': node.name
}
).property("full_name": node.full_name) \
.next()
For edge
g.merge_e({T.label: edge.relationship.value,
Direction.from_: edge.from_.id,
Direction.to: edge.to_.id})\
.option(Merge.on_create, {
T.label: edge.relationship.value
}) \
.option(Merge.on_match, {
'updated': "true"
}).property("description": edge.description).next()
For edge
g.merge_e({T.label: edge.relationship.value,
Direction.from_: edge.from_.id,
Direction.to: edge.to_.id})\
.option(Merge.on_create, {
T.label: edge.relationship.value
}) \
.option(Merge.on_match, {
'updated': "true"
}).property("description": edge.description).next()
In the edge, I don't want an "updated" thing to be there but if I keep the dictionary empty for the options, it throws the error. Let me know if I am doing it wrong or not. Should I place the values in the .property() or should I keep the changes in the options?
Gist
Gremlin merge() API
Gremlin merge() API. GitHub Gist: instantly share code, notes, and snippets.
3 Replies
Andrea
Andrea2mo ago
Hello @GojosEnsei what is the intended behaviour you are looking for if the edge exists already but you do not want to set the updated value to true?
GojosEnsei
GojosEnseiOP2mo ago
Hey @Andrea , thanks for the follow up. Sorry, I was a bit busy but after some experimentation I was able to do this myself. Actually I wanted to upsert. But I was not able to. But I figured out how to do that exactly. The key is to have some value always in on_match and on_create.
Andrea
Andrea2mo ago
Glad you found a workaround. Could you share what worked for you?

Did you find this page helpful?