2014-11-23 161 views
2

我很確定我應該看到我自己做的錯誤。我也很確定,我應該知道如何在java中構建一個體面的密碼查詢,但我根本無法。現在已經很晚了,自從過去4個小時以來,我一直對此感到震驚。所以,我放棄了。java neo4j密碼查詢匹配節點

我有一個相對簡單的暗號詢問我要執行對打開的事務端點

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 - 無論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: [email protected]{[email protected]{r=10,a=DISPATCHED,uri=/db/data/transaction/76},[email protected]{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: [email protected]{[email protected]{r=10,a=DISPATCHED,uri=\/db\/data\/transaction\/76},[email protected]{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 

我被卡住,現在感到沮喪。任何人都可以幫助我嗎?

感謝這麼多提前,

基督教

回答

3

與create,MATCH不能使用屬性MAP-它需要你使用文字。 所以您的查詢應該結束這樣看:

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

在你的第二個查詢,不要放在引號中的屬性鍵:

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

非常感謝。我得到它與您的答案一起工作。但是仍有一個問題。我如何獲得id,或者甚至更好的是通過上面的查詢找到的節點的url。我希望能夠通過查詢接收擴展json結構,所以我可以在json中使用自己的字段。但它看起來並不像返回。你能指導我嗎? – siliconchris 2014-11-24 20:28:43

+0

返回ID(p)會給你另一個帶有節點ID的列。如果您想要節點的完整URL,請在{「statements」中包含resultDataContents:[「REST」]:[{「statement」:「MATCH(p:SOCIALNETWORK {sn_id:'TW'})RETURN p」, 「resultDataContents」:[「REST」]}]}請參閱http://neo4j.com/docs/stable/rest-api-transactional.html#rest-api-execute-statements-in-an-open-transaction-in -rest-format-for-the return – Luanne 2014-11-25 03:58:22

+0

得到它的工作。對於所有人來說,她是一個 – siliconchris 2014-11-27 11:14:17

0

自2.0.5版本,你可以使用與MATCH¥and MERGE)屬性映射:

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

他們還沒有完全光滑如機智h CREATE但仍有改進。


¥不幸的是它的正式記錄只爲MERGE,而不是爲MATCH,但測試和你每天使用真正