How to get map of properties for Edge and Vertex in java?

132 views
Skip to first unread message

Mohit Shah

unread,
Sep 11, 2019, 10:52:13 AM9/11/19
to Gremlin-users
When I do query to get certain vertices or certain edges, I gets only id and label for edges and vertices.

I tried to use .valueMap().by(unfold()).with(WithOptions.tokens), but in java, I have to do a lot of parsing and it's getting tedious with bigger queries.

How can I get properties in ReferenceVertex objects while retrieving vertices? Any help would be appreciated.

Stephen Mallette

unread,
Sep 11, 2019, 10:59:30 AM9/11/19
to gremli...@googlegroups.com
The point of a "reference" is that it is just T.id and T.label, so there is no such approach to doing that. In fact, if you look at ReferenceVertex (in any language variant) you'll see that properties() are not even supported at the code level. I don't follow what you mean by "I have to do a lot of parsing and it's getting tedious with bigger queries."  How is working with a Map representation of a Vertex/Edge different from working with the Vertex/Edge itself if properties were included? Their structures are virtually identical.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e93e7d7e-91c5-45cb-88e1-c8fb1482e4b8%40googlegroups.com.

Mohit Shah

unread,
Sep 11, 2019, 11:10:42 AM9/11/19
to Gremlin-users
Ok got it. I guess I should just keep using Path to get edges and vertices using the answer provided by you from this link: https://stackoverflow.com/questions/33676566/gremlin-get-all-incoming-and-outgoing-vertex-including-their-edges-and-directio

I am also doing pagination in my queries, with that I need to specify step names and get the result for that step and parse the result. I found it a bit tedious. I was hoping to get properties with vertices and edges every time.

Stephen Mallette

unread,
Sep 11, 2019, 11:18:34 AM9/11/19
to gremli...@googlegroups.com
maybe you should provide some examples of what you're doing. i'm still trying to follow the "tedious" part...maybe there's an easier way that we can suggest?

On Wed, Sep 11, 2019 at 11:10 AM Mohit Shah <mohit....@gmail.com> wrote:
Ok got it. I guess I should just keep using Path to get edges and vertices using the answer provided by you from this link: https://stackoverflow.com/questions/33676566/gremlin-get-all-incoming-and-outgoing-vertex-including-their-edges-and-directio

I am also doing pagination in my queries, with that I need to specify step names and get the result for that step and parse the result. I found it a bit tedious. I was hoping to get properties with vertices and edges every time.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Mohit Shah

unread,
Sep 11, 2019, 11:31:02 AM9/11/19
to Gremlin-users
I have a graph like this.

User - FOLLOW -> Tag <- HAS - Content

User can follow tags and content will have tags.

HAS connection will have some kind of score.

I would like to get all tags followed by a user and 5 contents belong to individual tag sorted by score. (for every tag, sort contents by score present on HAS connection)

Example : 
User is following tag1, tag2, tag3.

content1 has tag1, tag2
content2 has tag2,tag3
content3 has tag1
content4 has tag1
content5 has tag2
content6 has tag1

Result : 

map of tags : 

tag1 -> list of sorted contents limit to 5, 
tag2 -> list of sorted contents limit to 5, 
tag3 -> list of sorted contents limit to 5

This is only 2 level queries, I also have some other complicated queries. I would always like to return a few attributes present on tags and contents.

Stephen Mallette

unread,
Sep 12, 2019, 7:41:40 AM9/12/19
to gremli...@googlegroups.com
well, that's you're query requirements, but that isn't demonstrating to me what part for you is tedious and difficult. can you please explain that part further? it would be helpful if you showed some actual Gremlin (e.g. a sample data generation script, the traversal that you're executing now, etc.)

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages