Return only a vertex's properties in Gremlin

74 views
Skip to first unread message

Johnny Weng Luu

unread,
Feb 3, 2012, 11:40:12 PM2/3/12
to ne...@googlegroups.com
If I am returning a vertex in Gremlin it will return a object with "data" and all Restful links.

Eg.

" ... return product"

would give me:

    data: { name: 'Products' },
    extensions: {},
...

Is it possible to return only the "data" part, that is only a vertex's properties

Peter Neubauer

unread,
Feb 4, 2012, 1:13:26 AM2/4/12
to ne...@googlegroups.com

Well,
If you still want the node returned but with a different, more compact and less hypermedia representation, we could add a compact one. Otherwise, you could do iterate over the properties of each node, put the resulting maps into a list and return that, since then you will get value representations of the content back, not a node representation.

Send from a device with crappy keyboard and autocorrection.

/peter

James Thornton

unread,
Feb 4, 2012, 1:54:45 AM2/4/12
to ne...@googlegroups.com
+1 on that. Rexster's format is nice and compact.

- James

Johnny Weng Luu

unread,
Feb 4, 2012, 4:39:51 AM2/4/12
to ne...@googlegroups.com
Yeah I think adding a compact one that means only the properties are returned is a good alternative. Sometimes you just don't need the other links and it would speed things up not returning them.

Johnny

Peter Neubauer

unread,
Feb 5, 2012, 10:25:11 AM2/5/12
to ne...@googlegroups.com
Issue raised,

https://github.com/neo4j/community/issues/211

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Matt Luongo

unread,
Feb 8, 2012, 8:31:10 AM2/8/12
to Neo4j
As cool as a compact format would be, if you only need properties just

return product.map()

should do it for now, right?

On Feb 5, 10:25 am, Peter Neubauer <peter.neuba...@neotechnology.com>
wrote:
> Issue raised,
>
> https://github.com/neo4j/community/issues/211
>
> Cheers,
>
> /peter neubauer
>
> G:  neubauer.peter
> S:  peter.neubauer
> P:  +46 704 106975
> L:   http://www.linkedin.com/in/neubauer
> T:   @peterneubauer
>
> Neo4j 1.6 released                 - dzone.com/6S4K
> The Neo4j Heroku Challenge   -http://neo4j-challenge.herokuapp.com/
>
> On Sat, Feb 4, 2012 at 10:39 AM, Johnny Weng Luu
>
>
>
>
>
>
>
> <johnny.weng....@gmail.com> wrote:
> > Yeah I think adding a compact one that means only the properties are
> > returned is a good alternative. Sometimes you just don't need the other
> > links and it would speed things up not returning them.
>
> > Johnny
>
> > On Sat, Feb 4, 2012 at 7:54 AM, James Thornton <james.thorn...@gmail.com>

Johnny Weng Luu

unread,
Feb 8, 2012, 10:56:00 AM2/8/12
to ne...@googlegroups.com
Hm never thought about that. I'll try that!

Johnny

Johnny Weng Luu

unread,
Feb 9, 2012, 5:44:10 PM2/9/12
to ne...@googlegroups.com
Btw, using map() to return a vertex would give me:

'{name=IT}'

Is there a way to return it as a JSON hash instead?

'{name: IT}'

Johnny

James Thornton

unread,
Feb 9, 2012, 5:47:46 PM2/9/12
to ne...@googlegroups.com
Oh, that's a known bug with the representation code:


The problem is that there is no Map converter so it falls through to convert the result to a String:

return ValueRepresentation.string( result.toString() );
 
And when converted to a String, a Java Map will look like this:

"{knows=2, likes=1}" 


- James

Peter Neubauer

unread,
Feb 10, 2012, 4:03:49 AM2/10/12
to ne...@googlegroups.com
This sux, I know.

Will try to look into it today.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Johnny Weng Luu

unread,
Feb 10, 2012, 8:26:03 AM2/10/12
to ne...@googlegroups.com
That would be helpful. 

In the meantime I just return the whole node and access the "data" property instead.

Johnny

Peter Neubauer

unread,
Feb 10, 2012, 8:33:52 AM2/10/12
to ne...@googlegroups.com
Here you go,
https://github.com/neo4j/community/commit/6b4bc74fae9206c8a9294773aede35347a8b249e

Will soon update the Gremlin plugin so maps are returned properly, see
https://github.com/neo4j/gremlin-plugin/commit/87d7275b6edb459a51636abecbd7f662fa72cc3e#L3R145


Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Johnny Weng Luu

unread,
Feb 10, 2012, 9:54:18 AM2/10/12
to ne...@googlegroups.com
Finally the irritating bug will be gone. Thanks Peter!

Johnny

Johnny Weng Luu

unread,
Feb 11, 2012, 9:49:58 PM2/11/12
to ne...@googlegroups.com
This was for the Blueprint method map() right?

At the moment I have to do:

new Neo4jVertex(node, g).map

Is there a way to return the same properties but on a Neo4j node without having to convert it to a Blueprint vertex and use map() on it?

Johnny

Peter Neubauer

unread,
Feb 12, 2012, 3:04:07 AM2/12/12
to ne...@googlegroups.com
Johnny,

you just collect the property keys and values in a map with a utility
function like

n = g.v(0).getRawVertex()
props = [:]
n.getPropertyKeys().each{props[it]=n.getProperty(it)}
props


which will return the props Map :)

/peter

Michael Hunger

unread,
Feb 12, 2012, 7:46:39 AM2/12/12
to ne...@googlegroups.com
if you you need a one-liner:

n.propertyKeys.collectEntries { [it , n.getProperty(it)] }

Johnny Weng Luu

unread,
Feb 12, 2012, 8:09:47 AM2/12/12
to ne...@googlegroups.com
The one liner is kinda simpler. Groovy is indeed more concise :)

Thanks both!

Johnny
Reply all
Reply to author
Forward
0 new messages