简体   繁体   中英

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:

{
    "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. Please suggest changes in query to acheive the values in json format.

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. 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:

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()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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