question

sankar avatar image
sankar asked jeromatron answered

How do I get all the properties of a vertex?

The query of g.V().hasId("customid") does return the vertex, but we are not able to get the properties of the vertex. What is the way to get the vertex with all the properties associated with it..

graphgremlin
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

jeromatron avatar image
jeromatron answered

Traditionally you would use the valueMap step to get the properties and optionally the id and label of the vertex.

g.V().hasId('customid').valueMap();

will return all of the properties of that vertex.

g.V().hasId('customid').valueMap(true);

will also return the ID and the label.

In recent versions of TinkerPop (and DS Graph), there is a cleaner alternative to valueMap called elementMap.

g.V().hasId('customid').elementMap();

and this is essentially equivalent to

g.V().hasId('customid').valueMap(true).by(unfold());

As a recommendation, I would always specify the vertex label with DataStax Graph because it allows the engine to know what vertex/table to start in. So I would do something like:

g.V().hasLabel('order').has('orderid', 1001).elementMap();

or more succinctly

g.V().has('order', 'orderid', 1001).elementMap();

See also

https://tinkerpop.apache.org/docs/current/reference/#elementmap-step
https://tinkerpop.apache.org/docs/current/reference/#valuemap-step
http://www.kelvinlawrence.net/book/PracticalGremlin.html#element-map
http://www.kelvinlawrence.net/book/PracticalGremlin.html#vm

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.