Gremlin filter by count

夙愿已清 提交于 2019-12-24 05:49:37

问题


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().



来源:https://stackoverflow.com/questions/50973693/gremlin-filter-by-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!