Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j 使用gremlin查询获得正确的结果_Neo4j_Cypher_Gremlin - Fatal编程技术网

Neo4j 使用gremlin查询获得正确的结果

Neo4j 使用gremlin查询获得正确的结果,neo4j,cypher,gremlin,Neo4j,Cypher,Gremlin,在neo4j中,我创建了两个节点,即CP和ANZ。我创建了两个边,分别为Sell和Buy between,该边的tx_amount属性分别为100和200 cp-->出售->100->澳新银行 澳新银行-->买入->200->CP 现在我要去拿卖家、买家、tx_金额。所以,如果我选择CP作为卖方。然后它应该打印如下: ==> [seller:CP, tx_amount:100, buyer:ANZ] ==> [seller:ANZ, tx_amount:200, buyer:CP]

在neo4j中,我创建了两个节点,即CP和ANZ。我创建了两个边,分别为Sell和Buy between,该边的tx_amount属性分别为100和200

cp-->出售->100->澳新银行

澳新银行-->买入->200->CP

现在我要去拿卖家、买家、tx_金额。所以,如果我选择CP作为卖方。然后它应该打印如下:

==> [seller:CP, tx_amount:100, buyer:ANZ]
==> [seller:ANZ, tx_amount:200, buyer:CP]
从上面的结果可以看出第一行返回有效输出,第二行的买方也正确。唯一的问题是第二行的卖方不是澳新银行,而是CP。那么,如何解决这个问题呢

当前查询,输出如下:

gremlin>g.v(0).outE().inV.as('seller')。bothE('Sell','Buy')。as('tx_amount')。inV.as('buyer')。选择{it.name}{it.amount}{it.name}。排序{it[2]}

        ==> [seller:CP, tx_amount:100, buyer:ANZ]
        ==> [seller:CP, tx_amount:200, buyer:CP]

我将headCustomerName作为根,然后在headCustomer和childcustomer之间定义一个子关系

g.V.has("headCustomerName","ABC Corp.").inE('child_rel').outV().as('buyer').outE('Sell_To').as('tx_amount').inV().as('seller')  \
      .select{it.customerName}{it.amount}{it.customerName}  
==>[buyer:CP, tx_amount:100, seller:ANZ]
==>[buyer:CP, tx_amount:200, seller:SS Tech]
==>[buyer:SAK Corp., tx_amount:400, Supplier:AB Infotech]
...
以及


谢谢。:)

无法一次将卖家和买家名称合并为俱乐部。:(我建议您添加更多上下文并描述您的问题,以便其他人能够理解,否则您将被否决或问题结束。我希望显示特定选定节点的供应商和买家。在我的案例中,请参见买家因()而发生变化)…任何其他方式都可以像使用循环或返回(?)或ifelsethen条件或反向概念一样。比如if(bothE('Sell'){print[supplier=left node,buyer=right node]}或者{print[supplier=right node,buyer=left node]}
g.V.has("headCustomerName","ABC Corp.").inE('child_rel').outV().as('seller').inE('Sell_To').as('tx_amount').outV().as('buyer')    \
      .select{it.customerName}{it.amount}{it.customerName}  
==>[seller:CP, tx_amount:1100, buyer:NEW Int]
==>[seller:CP, tx_amount:1300, buyer:Marry Gold]
==>[seller:SAK Corp., tx_amount:1006, buyer:LLI Corp.]
...