【问题标题】:Add a property to an already existing vertex in java在java中将属性添加到已经存在的顶点
【发布时间】:2019-04-04 14:19:34
【问题描述】:

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

您知道如何将新属性添加到已经存在的顶点吗?

【问题讨论】:

    标签: gremlin janusgraph gremlin-server


    【解决方案1】:

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

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

    根据需要添加属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 2018-06-20
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多