How to use ElasticSearch index in Titan Gremlin query?

不打扰是莪最后的温柔 提交于 2019-12-06 10:23:32

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/18191737/how-to-use-elasticsearch-index-in-titan-gremlin-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!