I want to export subgraph to json file and import in other graph. I tried as follows:
gremlin> subGraph = g.V().has("name","john").outE("has").subgraph("subgraph").cap("subgraph").next()
==>tinkergraph[vertices:6 edges:5]
now i have sub graph object then i used graphson to write this subgraph object directly to json file as follows:
subGraph.io(GraphSONIo.build()).writeGraph("/tmp/subgraph.json")
But i am getting error like this:
(was java.lang.IllegalStateException) (through reference chain: com.thinkaurelius.titan.graphdb.relations.RelationIdentifier["inVertexId"])
what is problem ??
I think the problem is that you have a TinkerGraph as your subgraph but that subgraph contains a Titan identifiers which GraphSON doesn't know how to natively process. You need to provide the Titan serializers to GraphSON so that it knows how to deal with the RelationIdentifier
. You don't say what version of Titan you are using, but I think this approach works regardless of the version:
mapper = GraphSONMapper.build().
addCustomModule(TitanGraphSONModule.getInstance()).
create()
writer = GraphSONWriter.build().mapper(mapper).create()
os = new FileOutputStream("/tmp/subgraph.json")
writer.writeGraph(os, subgraph)
The more modern approach for JanusGraph would be:
sg.io('/tmp/sample.json').
by(IO.registry, org.janusgraph.graphdb.tinkerpop.io.graphson.JanusGraphSONModuleV2d0.getInstance()).
write().iterate()