1

I am a newbie in Neo4j and facing a small problem.

I created around 5000 router nodes with its ipaddress property set to specific ip. Now I have around 5000 more interfaces and needs to create their nodes. I am using json and rest api for that in c++.

Every interface has a Routerip property and if the routerip matches the ipaddress of the router node that is already created I need to create that interface.

I have used this http://docs.neo4j.org/chunked/snapshot/rest-api-cypher.html#rest-api-create-mutiple-nodes-with-properties link to create my routers. Now I want to use the same method in order to create my interfaces. Is there a way wherein I can do so passing array of properties as paramaters in the cypher query and check for the router present to create my interface?

Nipun
  • 4,119
  • 5
  • 47
  • 83

2 Answers2

3

There are several ways to do this. Breaking it down into steps:

  • For each interface, find the matching router
  • Create the interface & connect the interface to that router

That would look something like

MATCH (router:Router)
WHERE router.ipaddress = props.RouterIp
CREATE (n:Interface { props } )-[:CONNECTED_TO]->(router)
Jacob Davis-Hansson
  • 2,603
  • 20
  • 26
  • and don't forget to create an index or constraint for fast lookups `create index on :Router(ipaddress)` – Michael Hunger Mar 29 '14 at 13:53
  • Hi, When I try to execute the query above using curl it gives error saying "props not defined ". – Nipun Apr 04 '14 at 09:23
  • @Nipun, then you haven't sent in the parameters as per the example you link to in your question. – nawroth Apr 04 '14 at 13:13
  • When I do this Create (R:Router {props}) return R; It works like a charm but when I do this match (R:Router) where R.ipaddress <> props.ipaddress create (R1:Router {props}) return R1 It says props not defined. Can someone please post an example where he has used a specific property from the array of properties in parameters in json. – Nipun Apr 04 '14 at 15:04
  • Hey When I try to run this simple query it gives me java exception – Nipun Apr 07 '14 at 05:46
0

Hey When I try to run this simple query as above it gives me java exception

{
   "params" : {
      "props" : [
         {
            "LocalAsNumber" : 0,
            "NodeDescription" : "10TiMOS-B-4.0.R2 ",
            "NodeId" : "10.227.28.95",
            "NodeName" : "BLR_WAO_SARF7"
         }
      ]
   },
   "query" : "MATCH (n:Router) where n.NodeId = {props}.NodeId  RETURN n"}

"message" : "The statement has been closed.", "exception" : "BadInputException", "fullname" : "org.neo4j.server.rest.repr.BadInputException", "stacktrace" : [ "org.neo4j.server.rest.repr.RepresentationExceptionHandlingIterable.exceptionOnHasNext(RepresentationExceptionHandlingIterable.java:50)", "org.neo4j.helpers.collection.ExceptionHandlingIterable$1.hasNext(ExceptionHandlingIterable.java:46)", "org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)", "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:71)", "org.neo4j.server.rest.repr.Serializer.serialize(Serializer.java:75)", "org.neo4j.server.rest.repr.MappingSerializer.putList(MappingSerializer.java:61)", "org.neo4j.server.rest.repr.CypherResultRepresentation.serialize(CypherResultRepresentation.java:83)", "org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:41)", "org.neo4j.server.rest.repr.OutputFormat.assemble(OutputFormat.java:215)", "org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(OutputFormat.java:147)", "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:130)", "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:67)", "org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:101)", "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)", "java.lang.Thread.run(Thread.java:744)" ],

Nipun
  • 4,119
  • 5
  • 47
  • 83