我看到多个示例(使用不同语言)都可以完成这个操作,这表明这应该可以工作。也许我漏掉了某个步骤?注释掉了指示我尝试过其他方法的行。
这是我获取我的“gremlin client”和“graphTraversalSource”直接使用的方法。
var gremlinServer = new GremlinServer(endpoint, 8182, enableSsl: true);
GremlinClient = new GremlinClient(gremlinServer);
//var remoteConnection = new DriverRemoteConnection(GremlinClient, "g");
var remoteConnection = new DriverRemoteConnection(GremlinClient);
//g = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);
g = new Graph().Traversal().WithRemote(remoteConnection);
如果我像这样将查询作为字符串提交:
var gndrSetCnt = GremlinQueryCount(GremlinClient, "g.V().count().next();");
var gndrResult = gndrSetCnt.Result;
and then....
private async Task<long> GremlinQueryCount(GremlinClient gremlinClient, string query)
{
return await gremlinClient.SubmitWithSingleResultAsync<long>(query);
}
虽然它笨拙,但仍可以正常工作。不过,如果我试图直接使用"g",像这样:
var example = g.V().Count().Next();
然后我会得到这样的错误信息:
Gremlin.Net.Driver.Exceptions.ResponseException: 'InvalidRequestArguments: {"detailedMessage":"A message with [bytecode] op code requires the [aliases] argument to be a Map containing one alias assignment named 'g'.","requestId":"ae024dd7-0fca-472b-acc6-7f717ca4bf2d","code":"InvalidParameterException"}'
我是否忽略了什么步骤?我在多个示例中看到过这种情况,似乎没有做其他任何操作,但我承认只有一个C#示例,并且那只是部分代码,更像是教程。貌似没有注入别名,g似乎默认可用?请注意,我在提交的Groovy脚本中使用g,它可以正常工作。据建议记录,我们添加了日志记录,以下是样本语句产生的内容:“RequestMessage {,requestId = 709ba190-0ce9-4272-aadb-4b28c21accf6,op ='bytecode',processor ='traversal',args = {gremlin = {$type = System.Collections.Generic.Dictionary
2 [[System.String, mscorlib],[System.Object, mscorlib]],mscorlib,@type = g:Bytecode,@value = {$type = System.Collections.Generic.Dictionary 2 [[System.String, mscorlib],[System.Collections.Generic.IEnumerable1[[System.Collections.Generic.IEnumerable
1[[System.Object, mscorlib]],mscorlib]],mscorlib,step ={$type = System.Linq.Enumerable+WhereSelectListIterator 2 [[Gremlin.Net.Process.Traversal.Instruction ,Gremlin.Net],[System.Collections.Generic.IEnumerable 1 [[System.Object,mscorlib]],mscorlib]],System.Core,$values = [[V],[hasLabel,article],[has,languageCode,fr-FR],[count]]}}},aliases = {$type = System.Collections.Generic.Dictionary 2 [[System.String,mscorlib],[System.Object,mscorlib]],mscorlib,g = g},$type = System.Collections.Generic.Dictionary 2 [[System.String,mscorlib],[System.Object,mscorlib]],mscorlib}}”我不确定这是否有帮助。原始错误消息表明,某种方式语句没有以“g”开头,但我不明白为什么会这样,因为我正在从具有“g”作为遍历源的drm中构建gts对象。
docker run --rm -p 8182:8182 -it tinkerpop/gremlin-server
。从你展示的代码来看,它应该在一般情况下能够运行。 - Florian Hockmann