问题
I'm getting weird results while writing a gremlin query. I can happily use the has function for most of the attributes for my nodes, for example "().has('name', 'VerisignCzagExtension').property('id')" will return v5086. But when I attempt to use the has function with the attribute id it never returns true. for example "().has('id', 'v5086').property('id')" returns no results. Anyone have any idea why this is happening?
Thanks.
回答1:
Internally, Neo4j stores all IDs as java.lang.Long
objects. This is a special behavior for id
property only. All other properties are stored with their implied data types. That's a reason why has('name', 'VerisignCzagExtension')
works (because name
property is excluded from this special behavior meant for id
). I'm assuming v5086
is being type casted to java.lang.Long
, thus losing it's real value. That could explain zero results after a has('id', 'v5086')
Gremlin step.
AFAIK, id
property is immutable (can't be changed). If you need to make id
look ups for vertices using a has
Gremlin step, it would look something like has('id', 5086L)
assuming that the vertex id
is 5086
and is being stored as a java.lang.Long
value. An extra L
is for explicit java.lang.Long
type-casting, Neo4j would assume java.lang.Integer
if you don't add that L
and your Gremlin step would result in zero results again.
Finally, you might want to call your named ID something else, like a property with key name
.
Hope this helps.
来源:https://stackoverflow.com/questions/14029227/how-to-get-an-attribute-named-id-in-gremlin