I'm trying to create (action)->(state) pair in such a way so that if :
- the action exists, use it, instead of creating new one
- the state exists, use it, instead of creating new one
and do it in single query.
The one I have creates new action node if the state is different, from previous calls. So I end up with multiple action nodes which are the same.
query = "merge (:state {id:%s})-[:q {q:%s}]->(:action {id:%s})" % (state, 0, action)
I use radis-graph.
The only way is to use 3 queries instead of 1 to achieve this :
graph.query mem 'merge (:state {id:9})'
graph.query mem 'merge (:action {id:9})'
graph.query mem 'match (s:state), (a:action) where s.id = 9 and a.id = 9 create (s)-[:q {q:0.3}]->(a)'