它不会添加具有正确进出顶点的边

It doesn't add an edges with the right in and out vertices

我想在两个顶点之间添加一条新边。

这是我正在使用的命令

def graph=ConfiguredGraphFactory.open('graph');
def g = graph.traversal();

graph.addVertex(label, 'Person', 'name', 'Jack', 'entityId', '100');
graph.addVertex(label, 'Person', 'name', 'John', 'entityId', '50');

def v1 = g.V().has('entityId', '100').next();
def v2 = g.V().has('entityId', '50').next();
v1.addEdge('managerOf',v2,'inEntityId', '100', 'outEntityId', '50')

然后每当我想获取我刚刚创建的路径时:

g.V().outE().inV().path();

它returns:

[
  {
    "labels": [
      [],
      [],
      []
    ],
    "objects": [
      {
        "id": 40968272,
        "label": "Person",
        "type": "vertex",
        "properties": {
          "name": [
            {
              "id": "oe22y-oe3bk-6mmd",
              "value": "Jack"
            }
          ],
          "entityId": [
            {
              "id": "oe2h6-oe3bk-6ozp",
              "value": "100"
            }
          ]
        }
      },
      {
        "id": "1crua2-oe3bk-4is5-oectk",
        "label": "managerOf",
        "type": "edge",
        "inVLabel": "Person",
        "outVLabel": "Person",
        "inV": 40980584,
        "outV": 40968272,
        "properties": {
          "outEntityId": "50",
          "inEntityId": "100"
        }
      },
      {
        "id": 40980584,
        "label": "Person",
        "type": "vertex",
        "properties": {
          "name": [
            {
              "id": "1cs5ql-oectk-6mmd",
              "value": "John"
            }
          ],
          "entityId": [
            {
              "id": "1cs64t-oectk-6ozp",
              "value": "50"
            }
          ]
        }
      }
    ]
  }
]

请注意,边缘并未反映我刚刚创建的内容。颠倒了!这怎么可能?我做错了什么吗?

我正在使用 JanusGraph,在数据浏览器中它也显示方向错误的边。

我认为是对的。尽管你处于优势地位,但你扭转了你的财产。 "outEntityId" 应该是“100”(杰克),"inEntityId" 应该是“50”(约翰),就像边缘是 inVoutV 反映的那样。换句话说,您创建了

jack-managerOf->john

对于那个 "managerOf" 边,边从 "jack" 出来,因此 outV 是 "jack",然后进入 "john",因此inV 是 "john"。

请注意,您可以通过使用遍历 API(又名 Gremlin)的推荐路线来简化 vertex/edge 添加:

gremlin> g.addV('Person').property('name', 'Jack').property('entityId', '100').as('jack').
......1>   addV('Person').property('name', 'John').property('entityId', '50').as('john').
......2>   addE('managerOf').from('jack').to('john').property('inEntityId', '50').property('outEntityId', '100').iterate()
gremlin> g.V().outE().inV().path().by('name').by(valueMap())
==>[Jack,[inEntityId:50,outEntityId:100],John]