0

How can I retrieve all vertex properties starting from the root vertex in Gremlin query?

We have the following structure:
Root Vertex: Employee

Edges: EdCompany, EdDepartment, EdRole
Vertices: Company, Department, Role

graph example

We are trying to receive the data of the other vertices joined with the root vertex. Somethink like this:

{
    "employee": [
        {
            "id": "1",
            "label": "Employee",
            "type": "vertex",
            "properties": { ... },
            "company": { 
                "id": "A220",
                "label": "Company",
                "type": "vertex",
                "properties": { ... }, 
            },
            "department": { ... },
            "edge": { ... }
        },
        { ... }
    ]
}

We have tried that query but return a complex JSON:

g.V().hasLabel("Employee").inE().outV().tree()

EDIT:

We have also tried the query suggested by Kelvin:

g.V().hasLabel("Employee").inE().outV().tree().by(valueMap())  

last test image screen

Stacktrace:
Failure in submitting query: g.V().hasLabel("Employee").inE().outV().tree().by(valueMap()): Server serialization error: ActivityId : 29f4b64e-c476-44b8-8e35-a07dd31d4242 ExceptionType : GraphSerializeException ExceptionMessage : Gremlin Serialization Error: GraphSON V1_0 serializer cannot serialize object of type: MapField to a primitive value to perform the desired Gremlin step

stfno.me
  • 898
  • 7
  • 24

1 Answers1

1

If all you need is the tree from the root you can just add a by(valueMap()) to your query to get the properties included as well. Such as:

g.V().hasLabel("Employee").
  inE().
  outV().
  tree().
    by(valueMap())
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • I have tried your query but it does not work. Check my edit please – stfno.me Aug 26 '21 at 10:34
  • It looks like you are using the GraphSON V1 serializer - please try with the V3 serializer or the GraphBinary serializer. It's not the query. It's the serializer being used. – Kelvin Lawrence Aug 26 '21 at 15:30
  • I can not use V3 because Azure Cosmos DB + Gremlin support V1/V2 serializer only. What can I do in this case? – stfno.me Aug 26 '21 at 16:15
  • I'm not sure what Cosmos does and does not support. You might try using just a single property key name as an experiment rather than `valueMap`. Have you tried the V2 serializer just in case? Does it support GraphBinary? – Kelvin Lawrence Aug 26 '21 at 20:43
  • I’ll try with single property key however V2 and GraphBinary does not work. Thanks for the support – stfno.me Aug 26 '21 at 20:48