Gremlin filter by count

2019-07-20 21:57发布

问题:

With the usage of this query in CosmosDB Gremlin API:

g.V().has('person', 'name', 'John').as('his')
.out('bought').aggregate('self')
.out('made_by')

I have next output:

[
  {
    "id": "100",
    "label": "brand",
    "type": "vertex",
    "properties": {
      "name": [
        {
          "id": "233b77e7-7007-4c08-8930-99b25b67e493",
          "value": "Apple"
        }
      ]
    }
  },
  {
    "id": "100",
    "label": "brand",
    "type": "vertex",
    "properties": {
      "name": [
        {
          "id": "233b77e7-7007-4c08-8930-99b25b67e493",
          "value": "Apple"
        }
      ]
    }
  },
  {
    "id": "101",
    "label": "brand",
    "type": "vertex",
    "properties": {
      "name": [
        {
          "id": "f3e238e2-f274-489c-a69c-f1333403ee8e",
          "value": "Google"
        }
      ]
    }
  }
]

Is there a way to select only brands, which quantity is > 1 (Apple in this case)?

回答1:

I think that you just need to groupCount() and then use a filter:

g.V().has('person', 'name', 'John').as('his').
  out('bought').aggregate('self').
  out('made_by').
  groupCount().
  unfold().
  where(select(values).is(gt(1))).
  select(keys)

You could just groupCount() and then unfold() the resulting Map so that you can filter the entries with where().