I want to check if the relation between two nodes exists or not. If exists I want to update the property else add new relation between specified nodes. A groovy script is used to read data from a CSV file and run the queries.
g.V().has('label_A','A').outE('to').inV().has('label_B','B').hasNext() ? g.V().has('label_A','A').outE('to').as('e').inV().has('label_B','B').select('e').property('created','existed') : g.V().has('label_A','A').as('fromV').V().has('label_B','B').as('toV').addE('to').from('fromV').to('toV').property('created','newAdded')
g.V().has('label_A','A').outE('to').inV().has('label_B','B').hasNext() is always returning false even if the relation exists between given two nodes when ran through groovy script. The same command on the gremlin console returns the expected output. Hence new relations are created always.
Also tried the following query
g.V().hasLabel('label_A','A').as('v').V().has('label_B','B').coalesce(__.inE('to').where(outV().as('v')),addE('to').from('v').property('created','newAdded')).property('created','existed')
The above query doesn't work. No relations are added.