graph - 使用树的 Gremlin 查询(JSON 输出)
问题描述
询问:
g.withSack(0).V().hasLabel('A').has('label_A','A').union(__.emit().repeat(sack(sum).by(constant(1)).in()),emit().repeat(sack(sum).by(constant(-1)).out())).project('level','properties').by(sack()).by(tree().by(valueMap().by(unfold())).unfold())
输出:
{
"level": 1,
"properties": {
"key": {
"label_A": "A"
},
"value": {
"{label_A=A}": {}
}
}
},
{
"level": 2,
"properties": {
"key": {
"label_A": "A"
},
"value": {
"{label_A=A}": {}
}
}
}
}
获取 json 格式的键而不是值。请建议更改查询以实现 json 格式的值。
解决方案
该步骤本质上以实例tree()
的形式返回树结构,因此输出与您的预期有关。在这种情况下,我想知道您是否需要使用并且可以改用 with ,因为它似乎在没有添加结构的情况下完成了相同的结果:Map
Map
tree()
path()
g.withSack(0).
V().hasLabel('A').has('label_A','A').
union(__.emit().repeat(sack(sum).by(constant(1)).in()),
emit().repeat(sack(sum).by(constant(-1)).out())).
project('level','properties').
by(sack()).
by(path().by(elementMap()))
推荐阅读
- iphone - 构建一个使用 React Native 创建的 iPhone 应用程序
- axon - 如何在 Saga 中测试具有内部状态的方法
- git - Git克隆和修改开源作为子目录并与master保持更新
- elasticsearch - 从 Elasticsearch 获取不同的字段
- javascript - Laravel 不导入/读取公共源文件 (css/js)
- c# - 如何使用 RegAsm 调用方法 C# Dll 方法?
- swift - Swift 4.2 UIDocumentBrowser View Controller Powerpoint PPTX 文件灰显
- database - symfony 对数据库表名有什么建议?
- ionic-framework - 如何从对讲或其他屏幕阅读器读取离子应用程序网络视图?
- unity3d - 如何知道 Unity Vuforia 中的地面检测是否丢失?