1
votes

Assumuing I have a graph with 'person' vertices. Each vertex have a 'name' and 'age' properties, except of one.

Now I'm trying to order by age:

g.V().order().by('age', asc).valueMap()

But it fails:

"The property does not exist as the key has no associated value for the provided element: v[328]:age"

Check this out: https://gremlify.com/ybbfwd2hbbc

How can I "replace" the missing properties with, let's say, 0? Thanks!

1

1 Answers

1
votes

You can use constant to fill out the missing values:

g.V().
  order().
    by(coalesce(
        values('age'),
        constant(0)
      ), asc).
  valueMap()

example: https://gremlify.com/qqhym71jlg

Or filter them ahead:

g.V().
  .has('age')
  order().
    by('age', asc).
  valueMap()

Example: https://gremlify.com/qqhym71jlg/1