CypherGremlinClient query runs very slow

Viewed 44

I am trying to run opencypher query using CypherGremlinClient.

this is how i initiate CypherGremlinClient.

 org.apache.commons.configuration.Configuration configuration = new BaseConfiguration();
        configuration.setProperty("port", neptuneProp.getPort());
        configuration.setProperty("hosts", neptuneProp.getOpencypherhost());
        configuration.setProperty("connectionPool.enableSsl", "true");
        Cluster cluster = Cluster.open(configuration);
        Client gremlinClient = cluster.connect();
        return CypherGremlinClient.translating(gremlinClient);

My query is

MATCH p=(n)-[r]->(d) WHERE ID(n) = '123' RETURN n,r 

this returns results with all attributes including ~id,~label which I need it for node and for Edges i am looking into ~id, _inV, _outV. but this query is running slow, most of the time I get memory error from neptune server.

Other side i am using below method which is executing query faster but does not return attributes that i am looking for.

    Config  neptunePropOpencypherConfig = Config.builder()
                    .withConnectionTimeout(30, TimeUnit.SECONDS)
                    .withMaxConnectionPoolSize(1000)
                    .withDriverMetrics()
                    .withLeakedSessionsLogging()
                    .withEncryption()
                    .withTrustStrategy(Config.TrustStrategy.trustSystemCertificates())
                    .build();
GraphDatabase.driver("bolt://" neptune.getHost() + ":" + neptuneProp.getPort(), neptunePropOpencypherConfig)

please help me to run my query faster with CypherGremlinClient or help me to get all other attributes using

Transaction readTx = readDiver.session().beginTransaction();
            Result results =  readTx.run("MATCH p=(n)-[r]->(d) WHERE ID(n) = '" + wgiId + "' RETURN n,r");

or if you know then suggest another approach.

I am looking for this kind of response.

{
  "results": [
    {
      "n": {
        "~id": "123",
        "~entityType": "node",
        "~labels": [
          "ontology"
        ],
        "~properties": {
          "lastrevid": 0,
          "P98": "1151332690",
          "labels": "{ \"de\" : [ \"Ivan Shedoff\" ] }",
          "aliases": "{ \"de\" : [ \"Ivan Shedoff\" ] }",
          "description": "{ }",
          "P26": "4.61517E+19"
        }
      },
      "r": {
        "~id": "123$11d27a77-1227-422c-9134-6e96d1cb7c79",
        "~entityType": "relationship",
        "~start": "123",
        "~end": "Q3",
        "~type": "claim",
        "~properties": {
          "claimCode": "P5"
        }
      }
    }
  ]
}
1 Answers

Neptune now supports openCypher as query language, see here. Support is currently in lab mode but soon to be GA.

Using the openCypher endpoint would be much easier than trying to do a translation. If you use the HTTPS endpoint you will get a result that is almost exactly what you specified above, an example is below

{
  "results": [
    {
      "a": {
        "~id": "22",
        "~entityType": "node",
        "~labels": [
          "airport"
        ],
        "~properties": {
          "desc": "Seattle-Tacoma",
          "lon": -122.30899810791,
          "runways": 3,
          "type": "airport",
          "country": "US",
          "region": "US-WA",
          "lat": 47.4490013122559,
          "elev": 432,
          "city": "Seattle",
          "icao": "KSEA",
          "code": "SEA",
          "longest": 11901
        }
      }
    }
  ]
}  
Related