java neo4j cypher查询匹配节点

时间:2014-11-23 21:28:42

标签: java neo4j cypher

我很确定我应该看到自己犯的错误。我也很确定,我应该知道如何在java中构建一个像样的密码查询,但我根本不能。已经很晚了,自从过去4个小时以来我就一直在努力。所以,我放弃了。

我想要针对开放事务端点执行相对简单的密码查询

 http://localhost:7474/db/data/transaction/[# number]

所以我想,我这样做就像我在创建节点时那样,但只是匹配而不是创建:

  {"statements": [ {"statement": "MATCH (p:POST {properties}) RETURN p", "parameters": {"properties":{"sn_id": "TW", "id": "536627264453353472"}} } ] }

但是服务器告诉我,我不能在匹配中使用参数映射:

  TRACE Neo4JPersistence - sending cypher {"statements": [ {"statement": "MATCH (p:POST {properties}) RETURN p", "parameters": {"properties":{"sn_id": "TW", "id": "536627264453353472"}} } ] } to endpoint http://localhost:7474/db/data/transaction/75
  TRACE Neo4JPersistence - GET to http://localhost:7474/db/data/transaction/75 returned status code 200, returned data: {"commit":"http://localhost:7474/db/data/transaction/75/commit","results":[],"transaction":{"expires":"Sun, 23 Nov 2014 21:09:05 +0000"},"errors":[{"code":"Neo.ClientError.Statement.InvalidSyntax","message":"Parameter maps cannot be used in MATCH patterns (use a literal map instead, eg. \"{id: {param}.id}\") (line 1, column 15)\n\"MATCH (p:POST {properties}) RETURN p\"\n               ^"}]}
  ERROR Neo4JPersistence - ERROR :: [{"message":"Parameter maps cannot be used in MATCH patterns (use a literal map instead, eg. \"{id: {param}.id}\") (line 1, column 15)\n\"MATCH (p:POST {properties}) RETURN p\"\n               ^","code":"Neo.ClientError.Statement.InvalidSyntax"}] - could not execute cypher statement at location http://localhost:7474/db/data/transaction/75

所以,好吧,我想。让我们选择更简单的东西吧,我就像这样构建了我的密码:

 {"statements": [ {"statement": "MATCH (p:SOCIALNETWORK {"sn_id": "TW"} ) RETURN p"} ] }

但是为此,服务器返回它不能反序列化请求并且它不喜欢s - 无论哪个是。

这是它的堆栈跟踪:

 TRACE Neo4JPersistence - sending cypher {"statements": [ {"statement": "MATCH (p:SOCIALNETWORK {"sn_id": "TW"} ) RETURN p"} ] } to endpoint http://localhost:7474/db/data/transaction/76
 TRACE Neo4JPersistence - GET to http://localhost:7474/db/data/transaction/76 returned status code 200, returned data: {"commit":"http://localhost:7474/db/data/transaction/76/commit","results":[],"transaction":{"expires":"Sun, 23 Nov 2014 21:18:01 +0000"},"errors":[{"code":"Neo.ClientError.Request.InvalidFormat","message":"Unable to deserialize request: Unexpected character ('s' (code 115)): was expecting comma to separate OBJECT entries\n at [Source: org.eclipse.jetty.server.HttpConnection$Input@43b86dc2{HttpChannelOverHttp@12dfe4a{r=10,a=DISPATCHED,uri=/db/data/transaction/76},HttpConnection@7291ace0{FILLING},g=HttpGenerator{s=START},p=HttpParser{s=END,87 of 87}}; line: 1, column: 59]"}]}
 ERROR Neo4JPersistence - ERROR :: [{"message":"Unable to deserialize request: Unexpected character ('s' (code 115)): was expecting comma to separate OBJECT entries\n at [Source: org.eclipse.jetty.server.HttpConnection$Input@43b86dc2{HttpChannelOverHttp@12dfe4a{r=10,a=DISPATCHED,uri=\/db\/data\/transaction\/76},HttpConnection@7291ace0{FILLING},g=HttpGenerator{s=START},p=HttpParser{s=END,87 of 87}}; line: 1, column: 59]","code":"Neo.ClientError.Request.InvalidFormat"}] - could not execute cypher statement at location http://localhost:7474/db/data/transaction/76

我现在感到困惑和沮丧。任何人都可以再次帮助我吗???

非常感谢,

基督教

2 个答案:

答案 0 :(得分:4)

与CREATE不同,MATCH不能使用属性映射 - 它要求您使用文字。 所以你的查询应该看起来像这样:

{
  "statements" : 
    [
      {
        "statement": "MATCH (p:SOCIALNETWORK {sn_id: {snid}} ) RETURN p",
        "parameters": {"snid": "TW"}
        }
    ]
}

在第二个查询中,请勿将属性键放在引号中:

{"statements": 
 [
  {
    "statement": "MATCH (p:SOCIALNETWORK {sn_id: 'TW'} ) RETURN p"
  } 
 ] 
}

答案 1 :(得分:0)

从版本2.0.5开始,您可以使用protocol MyDelegate{ func delegatedFunction(a:String) } class DelegatorClass { var delegate: MyDelegate! = nil func callDelegate() { delegate.delegatedFunction("hello") } } class DelegateClass: MyDelegate { var delegator:DelegatorClass = DelegatorClass() init() { delegator.delegate = self delegator.callDelegate() } func delegatedFunction (a:String){ print(a) } } ¥and MERGE)的属性映射:

public static void compareDirectories(DirectoryInfo Templatedir, DirectoryInfo Projectdir)
{
    DirectoryInfo[] recursiveTemplatedirs = Templatedir.GetDirectories("*.*");
    DirectoryInfo[] recursiveProjectdirs = Projectdir.GetDirectories("*.*");

    string recursiveName;
    string projectName;

    foreach (DirectoryInfo recursiveTemplatedir in recursiveTemplatedirs) 
    {
        recursiveName = recursiveTemplatedir.Name.ToString();
        foreach (DirectoryInfo recursiveProjectdir in recursiveProjectdirs)
        {
            projectName = recursiveProjectdir.Name.ToString();
            if (recursiveName == projectName) {
              Console.WriteLine("Match " + recursiveName);
            } else 
              Console.WriteLine("No Match " + recursiveName);

        compareDirectories(recursiveTemplatedir, recursiveProjectdir);
        }

    }
}

还不如MATCH那么顺利但仍有改进。

¥不幸的是,它仅在{ "statements" : [ { "statement": "MATCH (p:SOCIALNETWORK {sn_id: {properties}.sn_id)} ) RETURN p", "parameters": { "properties": {"snid": "TW"} } } ] } 而非CREATE正式记录,但是您的日常测试和使用