0

I'm new to all the graph database stuff and I'm having a hard time with some basic queries. I'm using Gremlin with Kotlin to connect to AWS Neptune. I want to get all my vertex properties including the Id.

I have added an vertex with:

g.addV("foo")
    .property("name", "Foo 1")
    .next()

And to retrieve the properties I have tried:

g.V()
    .hasLabel("foo")
    .valueMap<String>()
    .by(unfold<String>())
    .forEach {
        // val name = it["name"] -> works great!
        // val id = it["id"] -> doesn't exist
    }

In this first approach I get a map for each item but this map does not contain the ID.

g.V()
    .hasLabel("foo")
    .forEach {
        // it is an ReferenceVertex that has an ID!
        val name = it.property<String>("name") // This returns an EmptyVertexProperty, so I can't read the name
    }

I'm using

<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-driver</artifactId>
    <version>3.4.4</version>
</dependency>

Bonus question

I couldn't figure out (nor find in the documentation) what the generics on valueMap and unfold method do. Kotlin does not allow me to ommit them (as I have seem in some java code...?), but changing them to Int, for instance, changes nothing in the outcome for these examples... So what is it for? D:

Thanks in advance!

Moritz
  • 339
  • 1
  • 7
João Menighin
  • 3,083
  • 6
  • 38
  • 80

1 Answers1

2

If you want to get the Id with all the other properties you need to run valueMap().with(WithOptions.tokens) or you can use elementMap().

noam621
  • 2,766
  • 1
  • 16
  • 26
  • Hi noam, thanks! The `valueMap(true)` has been deprecated, but thanks to your answer I could find in the documentation the new way to do it, which is `valueMap().with(WithOptions.tokens)` as referenced [here](http://tinkerpop.apache.org/docs/3.4.0/upgrade/) in the `Modulation of valueMap()` section. Do you know anything about the `Bonus question`? – João Menighin Nov 22 '19 at 14:43
  • Thanks, I forget it was deprecated, I will edit my answer, also you can use ElementMap step. – noam621 Nov 22 '19 at 14:55
  • `elementMap` seemed like the best option. But it seems AWS Neptune does not implement it. I got `"InternalFailureException","detailedMessage":"Could not locate method: NeptuneGraphTraversal.elementMap()"` trying to use it. :/ Anyway, you answered my question. The bonus one I will try to find in the source code. Thanks! – João Menighin Nov 22 '19 at 15:01
  • you are right Neptune compatible to 3.4.1 and ````elementMap```` only from 3.4.4. sorry I couldn't help with the bonus question – noam621 Nov 22 '19 at 15:14