2013-09-30 2 views
3

Использование Neo4j 2.0.0-M5, я пытаюсь создать свою базу данных с помощью партии, как это объяснено в: http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.htmlBatch с уникальными отношениями

То, что я хочу сделать, это вставить узлы и отношения с «get_or_create», так что я могу запустить пакет несколько раз, не создавая избыточные узлы и отношения.

Создание уникальных узлов может быть сделано с /index/node/indexname?uniqueness=get_or_create, например:

POST /db/data/batch [ 
{"method":"POST","to":"/index/node/concept?uniqueness=get_or_create","id":0,"body":{"key":"nom", "value":"organisation", "properties": {"nom":"organisation"}}}, 
{"method":"POST","to":"/index/node/concept?uniqueness=get_or_create","id":1,"body":{"key":"nom", "value":"établissement", "properties": {"nom":"établissement"}}} 
] 

Однако я не нахожу как я могу создать уникальные отношения между двумя узлами индексированных?

Я хочу сказать, что между «établissement» и «организацией» существует «est». Если я пытаюсь с:

POST /db/data/batch [ 
{"method":"POST","to":"/index/node/concept?uniqueness=get_or_create","id":0,"body":{"key":"nom", "value":"organisation", "properties": {"nom":"organisation"}}}, 
{"method":"POST","to":"/index/node/concept?uniqueness=get_or_create","id":1,"body":{"key":"nom", "value":"établissement", "properties": {"nom":"établissement"}}}, 
{"method":"POST","to":"{1}/relationships","body":{"to":"{0}","type":"est"}}, 
{"method":"POST","to":"/index/relationship/my_rels?uniqueness=get_or_create","body":{"key":"nom","value":"est","uri":"{1}"}} 
] 

я получаю:

==> 500 Internal Server Error 
==> { 
==> "message" : "", 
==> "exception" : "BatchOperationFailedException", 
==> "fullname" : "org.neo4j.server.rest.domain.BatchOperationFailedException", 
==> "stacktrace" : ["org.neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:63)", "org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:188)", "org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)", "org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java:48)", "org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:123)", "org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:73)", "java.lang.reflect.Method.invoke(Method.java:606)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:132)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)" ] 
==> } 

я застрял с этой проблемой, так что любой совет будет очень ценен. Спасибо!

Грегуар

EDIT: проблема, кажется, выходит из-за ошибки, которая предотвращает уникальные узлы, которые будут ссылаться из партии: https://github.com/neo4j/neo4j/issues/84

ответ

1

обходного пути (как указано в GitHub ошибке вы упомянули) - использовать Cypher.

Пример использования Batch и Cypher:

[ 
    {"method":"POST","to":"/index/node/concept?uniqueness=get_or_create","id":0,"body":{"key":"nom", "value":"organisation", "properties": {"nom":"organisation"}}}, 
    {"method":"POST","to":"/index/node/concept?uniqueness=get_or_create","id":1,"body":{"key":"nom", "value":"établissement", "properties": {"nom":"établissement"}}}, 
    { 
     "method": "POST", 
     "to": "/cypher", 
     "id": 1, 
     "body": { 
      "query" : "START a=node:concept(nom={aVal}), b=node:concept(nom={bVal}) CREATE b-[r:est]->a RETURN a, b, r", 
      "params" : { 
      "aVal" : "établissement", 
      "bVal" : "organisation" 
      } 
     } 
    } 
] 

Выход:

[{ 
    "id": 0, 
    "location": "http://localhost:7474/db/data/index/node/concept/nom/organisation/18688", 
    "body": { 
     "extensions": {}, 
     "paged_traverse": "http://localhost:7474/db/data/node/18688/paged/traverse/{returnType}{?pageSize,leaseTime}", 
     "outgoing_relationships": "http://localhost:7474/db/data/node/18688/relationships/out", 
     "all_typed_relationships": "http://localhost:7474/db/data/node/18688/relationships/all/{-list|&|types}", 
     "traverse": "http://localhost:7474/db/data/node/18688/traverse/{returnType}", 
     "property": "http://localhost:7474/db/data/node/18688/properties/{key}", 
     "all_relationships": "http://localhost:7474/db/data/node/18688/relationships/all", 
     "self": "http://localhost:7474/db/data/node/18688", 
     "outgoing_typed_relationships": "http://localhost:7474/db/data/node/18688/relationships/out/{-list|&|types}", 
     "properties": "http://localhost:7474/db/data/node/18688/properties", 
     "incoming_relationships": "http://localhost:7474/db/data/node/18688/relationships/in", 
     "incoming_typed_relationships": "http://localhost:7474/db/data/node/18688/relationships/in/{-list|&|types}", 
     "create_relationship": "http://localhost:7474/db/data/node/18688/relationships", 
     "data": { 
      "nom": "organisation" 
     }, 
     "indexed": "http://localhost:7474/db/data/index/node/concept/nom/organisation/18688" 
    }, 
    "from": "/index/node/concept?uniqueness=get_or_create" 
}, { 
    "id": 1, 
    "location": "http://localhost:7474/db/data/index/node/concept/nom/%EF%BF%BDtablissement/18689", 
    "body": { 
     "extensions": {}, 
     "paged_traverse": "http://localhost:7474/db/data/node/18689/paged/traverse/{returnType}{?pageSize,leaseTime}", 
     "outgoing_relationships": "http://localhost:7474/db/data/node/18689/relationships/out", 
     "all_typed_relationships": "http://localhost:7474/db/data/node/18689/relationships/all/{-list|&|types}", 
     "traverse": "http://localhost:7474/db/data/node/18689/traverse/{returnType}", 
     "property": "http://localhost:7474/db/data/node/18689/properties/{key}", 
     "all_relationships": "http://localhost:7474/db/data/node/18689/relationships/all", 
     "self": "http://localhost:7474/db/data/node/18689", 
     "outgoing_typed_relationships": "http://localhost:7474/db/data/node/18689/relationships/out/{-list|&|types}", 
     "properties": "http://localhost:7474/db/data/node/18689/properties", 
     "incoming_relationships": "http://localhost:7474/db/data/node/18689/relationships/in", 
     "incoming_typed_relationships": "http://localhost:7474/db/data/node/18689/relationships/in/{-list|&|types}", 
     "create_relationship": "http://localhost:7474/db/data/node/18689/relationships", 
     "data": { 
      "nom": "�tablissement" 
     }, 
     "indexed": "http://localhost:7474/db/data/index/node/concept/nom/%EF%BF%BDtablissement/18689" 
    }, 
    "from": "/index/node/concept?uniqueness=get_or_create" 
}, { 
    "id": 1, 
    "body": { 
     "columns": ["a", "b", "r"], 
     "data": [ 
      [{ 
       "paged_traverse": "http://localhost:7474/db/data/node/18689/paged/traverse/{returnType}{?pageSize,leaseTime}", 
       "outgoing_relationships": "http://localhost:7474/db/data/node/18689/relationships/out", 
       "data": { 
        "nom": "�tablissement" 
       }, 
       "traverse": "http://localhost:7474/db/data/node/18689/traverse/{returnType}", 
       "all_typed_relationships": "http://localhost:7474/db/data/node/18689/relationships/all/{-list|&|types}", 
       "self": "http://localhost:7474/db/data/node/18689", 
       "all_relationships": "http://localhost:7474/db/data/node/18689/relationships/all", 
       "property": "http://localhost:7474/db/data/node/18689/properties/{key}", 
       "properties": "http://localhost:7474/db/data/node/18689/properties", 
       "outgoing_typed_relationships": "http://localhost:7474/db/data/node/18689/relationships/out/{-list|&|types}", 
       "incoming_relationships": "http://localhost:7474/db/data/node/18689/relationships/in", 
       "incoming_typed_relationships": "http://localhost:7474/db/data/node/18689/relationships/in/{-list|&|types}", 
       "extensions": {}, 
       "create_relationship": "http://localhost:7474/db/data/node/18689/relationships" 
      }, { 
       "paged_traverse": "http://localhost:7474/db/data/node/18688/paged/traverse/{returnType}{?pageSize,leaseTime}", 
       "outgoing_relationships": "http://localhost:7474/db/data/node/18688/relationships/out", 
       "data": { 
        "nom": "organisation" 
       }, 
       "traverse": "http://localhost:7474/db/data/node/18688/traverse/{returnType}", 
       "all_typed_relationships": "http://localhost:7474/db/data/node/18688/relationships/all/{-list|&|types}", 
       "self": "http://localhost:7474/db/data/node/18688", 
       "all_relationships": "http://localhost:7474/db/data/node/18688/relationships/all", 
       "property": "http://localhost:7474/db/data/node/18688/properties/{key}", 
       "properties": "http://localhost:7474/db/data/node/18688/properties", 
       "outgoing_typed_relationships": "http://localhost:7474/db/data/node/18688/relationships/out/{-list|&|types}", 
       "incoming_relationships": "http://localhost:7474/db/data/node/18688/relationships/in", 
       "incoming_typed_relationships": "http://localhost:7474/db/data/node/18688/relationships/in/{-list|&|types}", 
       "extensions": {}, 
       "create_relationship": "http://localhost:7474/db/data/node/18688/relationships" 
      }, { 
       "start": "http://localhost:7474/db/data/node/18688", 
       "data": {}, 
       "self": "http://localhost:7474/db/data/relationship/44187", 
       "property": "http://localhost:7474/db/data/relationship/44187/properties/{key}", 
       "properties": "http://localhost:7474/db/data/relationship/44187/properties", 
       "type": "est", 
       "extensions": {}, 
       "end": "http://localhost:7474/db/data/node/18689" 
      }] 
     ] 
    }, 
    "from": "/cypher" 
}] 
+1

Я забыл упомянуть, что в фактическом использовании вы хотите paramaterized значения в шифром. – LameCoder

Смежные вопросы