I've managed to set up Titan (v0.3.1) with Elastic Search in embedded mode, thanks to the Titan docs. However, my question is now: how do I take advantage of the ES indexing?
For example, I would like to use Text.CONTAINS
(which is supported, according to docs linked above). Specifically, I'd like to retrieve nodes with the string "abc"
somewhere in the value for a key called my_label
.
What syntax would achieve this goal from the Gremlin console?
Searching against an external index
The following query will use the Elasticsearch backend:
g.query().has('my_label',CONTAINS,'abc').edges()
In general, any has
query that contains three arguments will use your external index backend (Elasticsearch or Lucene).
The following query would perform an exact match instead:
g.query().has('my_label','abc').edges()
Getting your property key into the external index
graph.makeType().name("my_label").dataType(String.class).indexed("elastic", Vertex.class).unique(Direction.OUT).makePropertyKey();
The key difference between adding a Titan native index and an external index is the second parameter in the indexed(..)
call which indicates the name of the external index in which your property should be indexed.
Unfortunately right now, once a property exists with a certain key, you cannot add an index on that key; you would have to start with a fresh graph.
More information
The Titan docs are pretty easy to read:
https://github.com/thinkaurelius/titan/wiki/Indexing-Backend-Overview
(Bonus: Titan is being expanded to include other types of partial searching including prefix and regexp: https://github.com/thinkaurelius/titan/pull/311)