【问题标题】:Gremlin filter by countGremlin 按计数过滤
【发布时间】:2018-06-21 16:44:19
【问题描述】:

在 CosmosDB Gremlin API 中使用此查询:

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

我有下一个输出:

[
  {
    "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"
        }
      ]
    }
  }
]

有没有办法只选择数量大于 1 的品牌(在这种情况下是苹果)?

【问题讨论】:

    标签: azure-cosmosdb gremlin


    【解决方案1】:

    我认为你只需要groupCount() 然后使用过滤器:

    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)
    

    您可以只使用groupCount() 然后unfold() 生成Map,以便您可以过滤带有where() 的条目。

    【讨论】:

    • 看起来这正是我想要的。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    相关资源
    最近更新 更多