且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Titan Gremlin查询中使用ElasticSearch索引?

更新时间:2023-10-06 12:11:22

搜索外部索引

以下查询将使用Elasticsearch后端:

Searching against an external index

The following query will use the Elasticsearch backend:

g.query().has('my_label',CONTAINS,'abc').edges()

通常,任何包含三个参数的has查询都将使用您的外部索引后端(Elasticsearch或Lucene).

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()

graph.makeType().name("my_label").dataType(String.class).indexed("elastic", Vertex.class).unique(Direction.OUT).makePropertyKey();

添加Titan原生索引和外部索引之间的主要区别是indexed(..)调用中的第二个参数,该参数指示应在其中索引属性的外部索引的名称.

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.

Titan文档非常容易阅读: https://github.com/thinkaurelius/titan/wiki/Indexing-Backend-概述

The Titan docs are pretty easy to read: https://github.com/thinkaurelius/titan/wiki/Indexing-Backend-Overview

(奖励: Titan正在进行扩展,以包括其他类型的部分搜索,包括前缀和正则表达式: https://github.com/thinkaurelius/titan/pull/311 )

(Bonus: Titan is being expanded to include other types of partial searching including prefix and regexp: https://github.com/thinkaurelius/titan/pull/311)