简体   繁体   English

使用树的 Gremlin 查询(JSON 输出)

[英]Gremlin Query (JSON Output) using tree

Query:询问:

g.withSack(0).V().hasLabel('A').has('label_A','A').union(__.emit().repeat(sack(sum).by(constant(1)).in()),emit().repeat(sack(sum).by(constant(-1)).out())).project('level','properties').by(sack()).by(tree().by(valueMap().by(unfold())).unfold())

Output: Output:

{
    "level": 1,
    "properties": {
        "key": {
            "label_A": "A"
            
        },
        "value": {
            "{label_A=A}": {}
        }
    }
},
{
    "level": 2,
    "properties": {
        "key": {
            "label_A": "A"
          
        },
        "value": {
            "{label_A=A}": {}
            }
        }
    }
}

Getting keys in json format but not values.获取 json 格式的密钥,但不获取值。 Please suggest changes in query to acheive the values in json format.请建议更改查询以实现 json 格式的值。

The tree() step returns a tree structure in the form of a Map of Map instances essentially so the output is about what you can expect. tree()步骤以Map实例的Map形式返回树结构,因此 output 与您所期望的差不多。 In this case, I wonder if you need to use tree() and could instead get by with path() as it seems like it accomplishes the same result without the added structure:在这种情况下,我想知道您是否需要使用tree()并且可以使用path()来代替,因为它似乎在没有添加结构的情况下完成了相同的结果:

g.withSack(0).
  V().hasLabel('A').has('label_A','A').
  union(__.emit().repeat(sack(sum).by(constant(1)).in()),
        emit().repeat(sack(sum).by(constant(-1)).out())).
  project('level','properties').
    by(sack()).
    by(path().by(elementMap()))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM