Titan标准索引与弹性搜索索引

时间:2014-06-13 07:39:08

标签: elasticsearch titan

根据Titan Wiki,Titan标准索引只能执行完全匹配的查询, 并且使用弹性搜索将使我能够使用数字范围和全文搜索执行查询。

但是,当我执行以下WITHOUT elasticsearch时:

g=TitanFactory.open('e:/titan-cassandra.properties');
v=g.addVertex(null);
v.setProperty('mytext','i am the first vertex.');
v.setProperty('age',123);
v=g.addVertex(null);
v.setProperty('mytext','hello from a vertex.');
v.setProperty('age',456);
v=g.addVertex(null);
v.setProperty('mytext','hello world.');
v.setProperty('age',789);
System.out.println();
g.V.map;
System.out.println();
g.V.has('mytext',Text.REGEX,'.*vertex.*').map;
System.out.println();
g.V.has('mytext',Text.REGEX,'.*hello.*').map;
System.out.println();
g.V.has('age',Cmp.GREATER_THAN_EQUAL,200).has('age',Cmp.LESS_THAN_EQUAL,700).map;

我能够得到如下正确的结果:

==>{mytext=i am the first vertex., age=123}
==>{mytext=hello from a vertex., age=456}
==>{mytext=hello world., age=789}

==>null
==>{mytext=hello from a vertex., age=456}
==>{mytext=i am the first vertex., age=123}

==>null
==>{mytext=hello world., age=789}
==>{mytext=hello from a vertex., age=456}

==>null
==>{mytext=hello from a vertex., age=456}

我很好奇。为什么会这样? 我是否仍需要弹性搜索来执行正则表达式搜索或数值范围搜索?

感谢。

1 个答案:

答案 0 :(得分:3)

您在维基中阅读的内容是正确的。 Titan只能使用"标准指数"完全匹配。请注意当我在Titan控制台中尝试此代码时会发生什么:

gremlin> g.V.has('mytext',Text.REGEX,'.*vertex.*').map;
WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [(mytext REGEX .*vertex.*)]. For better performance, use indexes
==>{mytext=i am the first vertex., age=123}
==>{mytext=hello from a vertex., age=456}

如您所见,没有使用任何指数(标准或其他)。 Titan只是在内存中进行正则表达式评估。如果您在mytext上定义了一个ElasticSearch索引,Titan就会意识到这一点,并优化了查询以利用该索引,您就不会看到该消息。