Search code examples
neo4jjrubyneography

Neo4j + Neography Batch Import = BadInputException For input string: \"{0}\""


Platform:

  • Neo4j - Graph Database Kernel 2.0.0-M03 (server)
  • 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]
  • neography (1.1.1) for interaction with the neo4j REST api

I have a series of product nodes, with indexed catalogue number properties already stored in neo4j, and I'm attempting to batch insert SKUs that are children / variations of those products, with a relationship from the SKU -> the parent Product catalogue number

I have the following code:

#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

This returns back the error (full stack trace at the bottom)

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

Clearly I'm doing something wrong here, but I can't seem to see what it is. I'm wondering if there is something wrong with: [:get_node_index, PRODUCT_CATALOG_INDEX, :catalog_number, item[:catalog_number]], that isn't allowing the node reference of {0} ? I'm honestly not sure.

Any help is appreciated!

Full stack trace, with ,'s replaced with \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}]

Solution

  • You have it right. You can't use a result from an index as a single node reference because you can get a collection from that index lookup. (Say you index first name, and you get all the people named bob, and you get 10 back... problem.)

    So run the index query, get the first node id from the array that comes back and then pass that in to your your batch as proper id.