GraphHub uses the Gremlin graph traversal language to query the vertex data with the most edges

Project scenario: GraphHub uses the Gremlin graph traversal language to query the vertex data with the most edges

Project scenario: In the visual display interface, a graph structure with rich relational data needs to be displayed. Therefore, it is necessary to realize the query in the graph database, and the vertex data with the most edges.


Problem Description

Query the vertex data with the most edges in the graph database, and use Gremlin to query

1、查询出边最多的顶点
g.V().as('out').out()
.select('in')
.groupCount()
.unfold()
.filter(select(values).is(gt(0)))

Result display

insert image description here

2、查询入边最多的顶点
g.V().as('in').in()
.select('in')
.groupCount()
.unfold()
.filter(select(values).is(gt(0)))

Result display

insert image description here

3、查询两顶点关系最多的数据
g.V().as('out').out().as('in')
.select('out','in')
.groupCount()
.unfold()
.filter(select(values)
.is(gt(0)))

Result display

insert image description here

Program optimization:

The above scheme has obtained the basic statistical data of the value. Next, we need to obtain the most consistent statistical result.

1、查询出边最多的顶点
g.V().as('out').out()
.select('out')
.groupCount()
.unfold()
.filter(select(values)
.is(gt(0)))
.order()
.by(values, decr)
.select(keys)
.limit(1)

Result display

{
    
    
  "result": [
    {
    
    
      "label": "njcm",
      "type": "vertex",
      "properties": {
    
    
        "displayName": "",
        "g": "蜥形纲",
        "tz": "约10米,2008年居然发现了身长超过22米的鸭嘴龙。",
        "m": "脊索动物门",
        "create_time": 1675740718815,
        "tz1": "约4吨",
        "alias": [],
        "bpss": "每小时约20-25公里",
        "description": "",
        "fbqy": "北美、北极、中国",
        "identifier": "yzl",
        "name": "鸭嘴龙",
        "sx": "草食性",
        "k": "鸭嘴龙科",
        "s": "鸭嘴龙属",
        "scnd": "6500万-8000万年前,白垩纪晚期",
        "gs": [
          "{\"text\":\"鸭嘴龙(hadrosaurs) 为一类较大型的鸟臀类恐龙,最大的有15米多长。是白垩纪后期鸟盘目草食性恐龙家族的其中一员。}"
        ],
        "shxx": "鸭嘴龙...",
        "m1": "鸟臀目",
        "point_num": 15,
        "ym": "鸟脚亚目",
        "update_time": 1675749292041,
        "j": "动物界",
        "rate": 78.95
      },
      "id": "269d3090c8e045c29cf2118d66a9cf97"
    }
  ]
}
2、3查询优化效果一样

Parameter description:
.groupCount(): count the number of queries, according to the primary key;
.filter(select(values).is(gt(0))): filter data with a value greater than 0;
.order().by(values, decr) : Sort by value
. select(keys): Get the value of the vertex according to the primary key
. limit(1): Go to the first item at the front

Guess you like

Origin blog.csdn.net/Oaklkm/article/details/129126272