Search code examples
orientdb

How to omit key from an OCompositeKey?


I created an edge index for properties (out: Link, in: Link, type: String)

I would like to query the index without specifying the type property via:

Iterable<Edge> edges = noTrx.getEdges("e." + label, new OCompositeKey(vertexA.getId(), vertexB.getId()));

Unfortunately no element could be found if i omit the type from the OCompositeKey.

Is there a way to query the index and omit the type? Or do I need to create a dedicated index which just contains out and in?

Full example source:

https://github.com/Jotschi/orientdb-playground/blob/e5bb027df171a04bc87d3b108ee58cc86499b7c3/src/test/java/de/jotschi/orientdb/EdgeIndexTest.java


Solution

  • You use hash index, so provided approach is correct. But if you will use tree based index and work with embedded database, you may use a composite key without type but in a bit tricky manner. Instead of calling of getEdges function you should call

    index.iterateEntriesMajor(new OCompositeKey(root.getId(), foundElement.getId()))

    And then for each record in result call graph.getEdge(record)

    I noticed that you use noTX graph implementation, I do not suggest to use the noTx implementation in production, it may lead to data inconsistency and broken graph state.