Search code examples
graphgremlintinkerpoptinkerpop3gremlin-server

How to update the Vertex/Edge ID in Gremlin?


How to update the vertex/Edge ID?

g.V('jesica@rickandmorty.com').property(T.id, 'jerry@rickandmorty.com')

Getting the following error in Gremlin.version() ==>3.4.10.

{"detailedMessage":"org.apache.tinkerpop.gremlin.structure.T$2 
    cannot be cast to java.lang.String","requestId":"ade01b34-8eec-46c4-9901-62dc1034f239",
       "code":"UnsupportedOperationException"}

Solution

  • The id and label of a Vertex (or Edge for that matter) is immutable. If you want to change the id you would have to remove the Vertex and then add it back. The error message is a bit misleading in older versions of Gremlin. As of 3.4.11 it now reads:

    gremlin> g.V(1).property(T.id, 200).iterate();
    T.id is immutable on existing elements
    Type ':help' or ':h' for help.
    Display stack trace? [yN]y
    java.lang.IllegalStateException: T.id is immutable on existing elements