问题描述
我已经看到了许多完成此操作的示例(各种语言),这表明应该可行。也许我错过了一步?注释掉表明我已经尝试过的其他事情的行。
这是我如何获取我的gremlin客户端以及一个直接使用的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;
然后....
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 ='字节码',处理器='遍历',args = {gremlin = {$ type = System.Collections.Generic.Dictionary {{1 }} 2 [[[System.String,mscorlib],[System.Collections.Generic.IEnumerable 2[[System.String,mscorlib],[System.Object,mscorlib]],mscorlib,@type=g:Bytecode,@value={$type=System.Collections.Generic.Dictionary
1 [[System.Object,mscorlib]],mscorlib]],mscorlib]],mscorlib,step = {$ type = System.Linq.Enumerable + WhereSelectListIterator 1[[System.Collections.Generic.IEnumerable
1 [[System.Object,mscorlib]],mscorlib]],System.Core,$ values = [[V],[hasLabel,商品],[具有, languageCode,fr-FR],[count]]}}},别名= {$ type = System.Collections.Generic.Dictionary 2[[Gremlin.Net.Process.Traversal.Instruction,Gremlin.Net],[System.Collections.Generic.IEnumerable
2 [[System.String,mscorlib],[System.Object,mscorlib] ],mscorlib}}“
我不确定是否有帮助。原始错误消息表明,该语句以某种方式不是以“ g”开头,但鉴于我正在执行的操作,我不明白为什么不是这样-这是从具有“ g”的drm构建gts对象”作为遍历来源。
解决方法
您建立连接的方法是正确的,尽管现在已不建议这样做。您现在应该使用:
g = Traversal().withRemote(remoteConnection);
但是,这不是导致您的问题的原因。 Neptune期待包含别名“ g”的请求。最好在群集上启用审核日志记录,以查看您的代码作为别名而不是“ g”发送的确切信息。