Bob Wilson
Bob Wilson

Reputation: 21

How to speed up parsing Neo4j ExecutionResult set?

I am running a two part Neo4j search which is performing well. However, the actual parsing of the ExecutionResult set is taking longer than the Cypher query by a factor of 8 or 10. I'm looping through the ExecutionResult map as follows:

result = engine.execute("START facility=node({id}), service=node({serviceIds}) WHERE    facility-->service RETURN facility.name as facilityName, service.name as serviceName", cypherParams);

for ( Map<String, Object> row : result )
{           
    sb.append((String) row.get("facilityName")+" : " + (String) row.get("serviceName") + "<BR/>" );
}

Any suggestions for speeding this up? Thanks

Upvotes: 0

Views: 222

Answers (1)

tstorms
tstorms

Reputation: 5001

Do you need access to entities or is it sufficient to work with nodes (and thus use the core API)? In the latter case, you could use the traversal API which is faster than Cypher.

I'm not sure what your use case is, but depending on the scenario, you could probably do something like this:

   for (final Path position : Traversal.description().depthFirst()
       .relationships(YOUR_RELATION_TYPE, Direction.INCOMING)
       .uniqueness(Uniqueness.NODE_RECENT)
       .evaluator(Evaluators.toDepth(1)
       .traverse(facilityNode,serviceNode)) {
        // do something like e.g. position.endNode().getProperty("name")
    }

Upvotes: 1

Related Questions