0

平台:

  • Neo4j - 图形数据库内核 2.0.0-M03(服务器)
  • jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_25-b15 [linux-amd64]
  • 用于与 neo4j REST api 交互的neography (1.1.1)

我有一系列产品节点,索引目录号属性已经存储在 neo4j 中,我正在尝试批量插入作为这些产品的子/变体的 SKU,与 SKU -> 父产品目录号的关系

我有以下代码:

#items is an array of skus

items.each do |item|
    commands = []

    #get the node we want to create a relationship to
    commands << [:get_node_index, PRODUCT_CATALOG_INDEX, :catalog_number, item[:catalog_number]]
    commands << [:create_node, {sku: item[:sku]}]
    commands << [:add_node_to_index, PRODUCT_SKU_INDEX, :sku, item[:itemnumber], '{1}']
    commands << [:create_relationship, "product_variation_of", '{1}', '{0}']

    @neo.batch *commands

end

这将返回错误(底部的完整堆栈跟踪)

, "body"=>{"message"=>"For input string: \"{0}\""
, "exception"=>"BadInputException"
, "fullname"=>"org.neo4j.server.rest.repr.BadInputException"

显然我在这里做错了什么,但我似乎看不到它是什么。我想知道是否有问题:[:get_node_index, PRODUCT_CATALOG_INDEX, :catalog_number, item[:catalog_number]],不允许 {0} 的节点引用?老实说,我不确定。

任何帮助表示赞赏!

完整的堆栈跟踪,用 , 替换为\n

  E
, [2013-07-25T19:18:37.080000 #29182] ERROR -- : 400 error: [{"id"=>0
, "from"=>"/index/node/product_catalog_number/catalog_number/1234"
, "body"=>[{"extensions"=>{}
, "outgoing_relationships"=>"http://dev.local:7474/db/data/node/531/relationships/out"
, "labels"=>"http://dev.local:7474/db/data/node/531/labels"
, "all_typed_relationships"=>"http://dev.local:7474/db/data/node/531/relationships/all/{-list|&|types}"
, "traverse"=>"http://dev.local:7474/db/data/node/531/traverse/{returnType}"
, "self"=>"http://dev.local:7474/db/data/node/531"
, "property"=>"http://dev.local:7474/db/data/node/531/properties/{key}"
, "properties"=>"http://dev.local:7474/db/data/node/531/properties"
, "outgoing_typed_relationships"=>"http://dev.local:7474/db/data/node/531/relationships/out/{-list|&|types}"
, "incoming_relationships"=>"http://dev.local:7474/db/data/node/531/relationships/in"
, "create_relationship"=>"http://dev.local:7474/db/data/node/531/relationships"
, "paged_traverse"=>"http://dev.local:7474/db/data/node/531/paged/traverse/{returnType}{?pageSize
,leaseTime}"
, "all_relationships"=>"http://dev.local:7474/db/data/node/531/relationships/all"
, "incoming_typed_relationships"=>"http://dev.local:7474/db/data/node/531/relationships/in/{-list|&|types}"
, "data"=>{"title"=>"MY PRODUCT"
, "catalog_number"=>"1234"}
, "indexed"=>"http://dev.local:7474/db/data/index/node/product_catalog_number/catalog_number/1234/531"}]
, "status"=>200}
, {"id"=>1
, "from"=>"/node"
, "body"=>{"extensions"=>{}
, "outgoing_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/out"
, "labels"=>"http://dev.local:7474/db/data/node/1239/labels"
, "all_typed_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/all/{-list|&|types}"
, "traverse"=>"http://dev.local:7474/db/data/node/1239/traverse/{returnType}"
, "self"=>"http://dev.local:7474/db/data/node/1239"
, "property"=>"http://dev.local:7474/db/data/node/1239/properties/{key}"
, "properties"=>"http://dev.local:7474/db/data/node/1239/properties"
, "outgoing_typed_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/out/{-list|&|types}"
, "incoming_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/in"
, "create_relationship"=>"http://dev.local:7474/db/data/node/1239/relationships"
, "paged_traverse"=>"http://dev.local:7474/db/data/node/1239/paged/traverse/{returnType}{?pageSize
,leaseTime}"
, "all_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/all"
, "incoming_typed_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/in/{-list|&|types}"
, "data"=>{"sku"=>"0320442A5"}}
, "location"=>"http://dev.local:7474/db/data/node/1239"
, "status"=>201}
, {"id"=>2
, "from"=>"/index/node/product_sku"
, "body"=>{"extensions"=>{}
, "outgoing_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/out"
, "labels"=>"http://dev.local:7474/db/data/node/1239/labels"
, "all_typed_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/all/{-list|&|types}"
, "traverse"=>"http://dev.local:7474/db/data/node/1239/traverse/{returnType}"
, "self"=>"http://dev.local:7474/db/data/node/1239"
, "property"=>"http://dev.local:7474/db/data/node/1239/properties/{key}"
, "properties"=>"http://dev.local:7474/db/data/node/1239/properties"
, "outgoing_typed_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/out/{-list|&|types}"
, "incoming_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/in"
, "create_relationship"=>"http://dev.local:7474/db/data/node/1239/relationships"
, "paged_traverse"=>"http://dev.local:7474/db/data/node/1239/paged/traverse/{returnType}{?pageSize
,leaseTime}"
, "all_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/all"
, "incoming_typed_relationships"=>"http://dev.local:7474/db/data/node/1239/relationships/in/{-list|&|types}"
, "data"=>{"sku"=>"0320442A5"}
, "indexed"=>"http://dev.local:7474/db/data/index/node/product_sku/sku/0320442A5/1239"}
, "location"=>"http://dev.local:7474/db/data/index/node/product_sku/sku/0320442A5/1239"
, "status"=>201}
, {"id"=>3
, "from"=>"http://dev.local:7474/db/data/node/1239/relationships"
, "body"=>{"message"=>"For input string: \"{0}\""
, "exception"=>"BadInputException"
, "fullname"=>"org.neo4j.server.rest.repr.BadInputException"
, "stacktrace"=>["org.neo4j.server.rest.web.RestfulGraphDatabase.extractNodeId(RestfulGraphDatabase.java:199)"
, "org.neo4j.server.rest.web.RestfulGraphDatabase.createRelationship(RestfulGraphDatabase.java:564)"
, "java.lang.reflect.Method.invoke(Method.java:606)"
, "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"
, "org.neo4j.server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:291)"
, "org.neo4j.server.rest.web.StreamingBatchOperations.invoke(StreamingBatchOperations.java:66)"
, "org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:188)"
, "org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)"
, "org.neo4j.server.rest.web.StreamingBatchOperations.readAndExecuteOperations(StreamingBatchOperations.java:54)"
, "org.neo4j.server.rest.web.BatchOperationService$1.write(BatchOperationService.java:89)"
, "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"]
, "cause"=>{"message"=>"For input string: \"{0}\""
, "exception"=>"NumberFormatException"
, "fullname"=>"java.lang.NumberFormatException"
, "stacktrace"=>["java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)"
, "java.lang.Long.parseLong(Long.java:441)"
, "java.lang.Long.parseLong(Long.java:483)"
, "org.neo4j.server.rest.web.RestfulGraphDatabase.extractNodeId(RestfulGraphDatabase.java:195)"
, "org.neo4j.server.rest.web.RestfulGraphDatabase.createRelationship(RestfulGraphDatabase.java:564)"
, "java.lang.reflect.Method.invoke(Method.java:606)"
, "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"
, "org.neo4j.server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:291)"
, "org.neo4j.server.rest.web.StreamingBatchOperations.invoke(StreamingBatchOperations.java:66)"
, "org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:188)"
, "org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)"
, "org.neo4j.server.rest.web.StreamingBatchOperations.readAndExecuteOperations(StreamingBatchOperations.java:54)"
, "org.neo4j.server.rest.web.BatchOperationService$1.write(BatchOperationService.java:89)"
, "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"]}}
, "status"=>400}]
4

2 回答 2

2

你说得对。您不能将索引的结果用作单个节点引用,因为您可以从该索引查找中获取集合。(假设你索引名字,你得到所有叫 bob 的人,你得到 10 回......问题。)

因此,运行索引查询,从返回的数组中获取第一个节点 ID,然后将其作为正确的 ID 传递给您的批处理。

于 2013-07-25T22:56:45.020 回答
1

标识符{0}等现在只能引用索引获取命令未设置的位置标头,因为它们可以返回任意数量的节点。

AFAIK get-or-create 命令设置正确的位置标头。

POST http://localhost:7474/db/data/index/node/PRODUCT_CATALOG_INDEX?uniqueness=get_or_create \
{"key" : "catalog_number","value" : item[:catalog_number],\
 "properties" : {"catalog_number" : item[:catalog_number]}}
于 2013-07-26T01:01:16.767 回答