How do I update a specific edge property using Gremlin/Titan/TinkerPop3?
<h3>The goal</h3>
<p>I have a simple enough task to accomplish: Set the weight of a specific edge property. Take this scenario as an example:</p>
<p><a href="https://i.stack.imgur.com/uYlTz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uYlTz.png" alt="Example Graph Structure" /></a></p>
<p>What I would like to do is update the value of <code>weight</code>.</p>
<p><strong>Additional Requirements</strong></p>
<ul>
<li>If the edge does not exist, it should be created.</li>
<li>There may only exist at most one edge of the same type between the two nodes (i.e., there can't be multiple &quot;votes_for&quot; edges of <code>type</code> &quot;eat&quot; between Joey and Pizza.</li>
<li>The task should be solved using the <a href="http://titan.thinkaurelius.com/javadoc/1.0.0/" rel="noreferrer">Java API of Titan</a> (which includes Gremlin as part of <a href="https://tinkerpop.apache.org/" rel="noreferrer">TinkerPop 3</a>).</li>
</ul>
<hr />
<h3>What I know</h3>
<p>I have the following information:</p>
<ul>
<li>The <a href="http://tinkerpop.apache.org/javadocs/3.2.2/core/org/apache/tinkerpop/gremlin/structure/Vertex.html" rel="noreferrer">Vertex</a> labeled &quot;user&quot;</li>
<li>The edge label <code>votes_for</code></li>
<li>The value of the edge property <code>type</code> (in this case, &quot;eat&quot;)</li>
<li>The value of the property <code>name</code> of the vertex labeled &quot;meal&quot; (in this case &quot;pizza&quot;), and hence also its <a href="http://tinkerpop.apache.org/javadocs/3.2.2/core/org/apache/tinkerpop/gremlin/structure/Vertex.html" rel="noreferrer">Vertex</a>.</li>
</ul>
<h3>What I thought of</h3>
<p>I figured I would need to do something like the following:</p>
<ol>
<li>Start at the Joey vertex</li>
<li>Find all outgoing edges (which should be at most 1) labeled <code>votes_for</code> having <code>type</code> &quot;eat&quot; and an outgoing vertex labeled &quot;meal&quot; having <code>name</code> &quot;pizza&quot;.</li>
<li>Update the <code>weight</code> value of the edge.</li>
</ol>
<p>This is what I've messed around with in code:</p>
<pre><code>//vertex is Joey in this case
g.V(vertex.id())
    .outE(&quot;votes_for&quot;)
    .has(&quot;type&quot;, &quot;eat&quot;)
    //... how do I filter by .outV so that I can check for &quot;pizza&quot;?
    .property(Cardinality.single, &quot;weight&quot;, 0.99);
    //... what do I do when the edge doesn't exist?
</code></pre>
<p>As commented in code there are still issues. Would explicitly specifying a Titan schema help? Are there any helper/utility methods I don't know of? Would it make more sense to have several <code>vote_for</code> labels instead of one label + <code>type</code> property, like <code>vote_for_eat</code>?</p>
<p>Thanks for any help!</p>