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

时间:2019-04-04 14:19:35

标签: gremlin janusgraph gremlin-server

我正在尝试向远程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文档以及各种教程/网站,但只找到了一种添加属性属性的方法(参见{How to add property to vertex property in java?

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

1 个答案:

答案 0 :(得分:0)

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

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

根据需要添加属性