2

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?

bcm360
  • 1,437
  • 2
  • 17
  • 25

1 Answers1

3

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)

Community
  • 1
  • 1
Jonathan Schneider
  • 26,852
  • 13
  • 75
  • 99
  • Thanks, @jkschneider. Great to see the new search functionality on the way & thanks for your contributions to a great project. Quick follow-up: how do I explicitly add `my_label` to the ES index (or do I need to)? I'm finding that once a vertex is created with a `my_label` property, the 3-param `has` syntax you mention above comes back with `Invalid data type for condition: class java.lang.Object`. – bcm360 Aug 19 '13 at 16:09
  • 1
    The index would be created like this (see the "Indexing Backend Overview" document page): `graph.makeType().name("my_label").dataType(String.class).indexed("elastic", Vertex.class).unique(Direction.OUT).makePropertyKey();` 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. I've been putting some thought into changing that, but you have to imagine that adding an index on the fly would make the external index more inconsistent than normal while it catches up. – Jonathan Schneider Aug 19 '13 at 18:58