将 属性 添加到 java 中已经存在的顶点

Add a property to an already existing vertex in java

我正在尝试将 属性 添加到远程 gremlin 服务器上的现有顶点。

顶点的创建方式如下:

String LABEL = "label";
String NAME = "name";
String ID = "id";
String TEST = "test";

GryoMessageSerializerV3d0 serializer = new GryoMessageSerializerV3d0(GryoMapper.build().addRegistry(TinkerIoRegistryV3d0.instance()));
cluster = Cluster.build().addContactPoint("localhost").port(8182).serializer(serializer).create();
client = cluster.connect();
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = JanusGraphFactory.open("/Users/user/Documents/stage/tinkerPop/Project/janusgraph-eval/janusgraph-0.3.1/conf/gremlin-server/janusgraph-cql-es-server.properties").traversal().withRemote(DriverRemoteConnection.using(cluster));
final Bindings b = Bindings.instance();
Vertex v1 = g.addV(b.of(LABEL, "transaction")).property(NAME, b.of(NAME, nameOfVertex1)).property(ID, b.of(ID, id1)).next();

这样做:

g.V(v1).property(VertexProperty.Cardinality.single, TEST, b.of(TEST, "test")).next();

或者这个:

GraphTraversal v1 = g.addV(b.of(LABEL, "transaction")).property(NAME, b.of(NAME, nameOfVertex1)).property(ID, b.of(ID, id1));
v1.property(VertexProperty.Cardinality.single, TEST, b.of(TEST, "test")).next();

给我以下错误:

java.util.concurrent.CompletionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: The type of given name is not a key: test

我查看了 tinkerpop 文档和各种 tutorials/websites,但我只找到了一种添加属性属性的方法(参见

您知道如何向现有顶点添加新的 属性 吗?

我发现使用 GremlinPipeline 可以解决问题。

GremlinPipeline pipe = new GremlinPipeline();
pipe.start(g.V(id).property("name", "value").next());

根据需要添加 属性