Search code examples
graphgremlinorientdb

Tinkerpop - how do I find a node in the graph?


I can't seem to find a specific node in the graph without traversing the whole thing. Is there something I'm missing?

I'm using tinkerpop blueprints.

Orientdb gives some sort of unsemantic id to a node such as '#8:1' - how do I find this without knowing the id? vertex has a property like 'user=jason' that will identify it. I'm thinking I'll just use redis to store the user/location pair or otherwise use a supernode (no thanks)


Solution

  • Blueprints has the notion of key indices.

    https://github.com/tinkerpop/blueprints/wiki/Graph-Indices

    Given your example, define a key index for "user", then query it with the key index. Here's an example using OrientDB from a Gremlin prompt:

    gremlin> g = new OrientGraph("memory://graph")
    ==>orientgraph[memory://graph]
    gremlin> g.createKeyIndex("user", Vertex.class)
    ==>null
    gremlin> g.addVertex([user:"Jason"])
    ==>v[#8:-3]
    gremlin> g.addVertex([user:"Rick"])
    ==>v[#8:-4]
    gremlin> g.stopTransaction(SUCCESS)
    ==>null
    gremlin> g.V('user','Jason')
    ==>v[#8:1]