当使用Titan 1.0.0
和Elasticsearch作为我的索引后端时,我创建了以下混合索引:
TitanGraph titanGraph = TitanFactory.open("titan-cassandra-es.properties");
TitanManagement management = graph.openManagement();
PropertyKey typeKey = management.makePropertyKey("TYPE").dataType(String.class).make();
PropertyKey degreeKey = management.makePropertyKey("DEGREE").dataType(Long.class).make();
management.buildIndex("byTypeDegree", Vertex.class)
.addKey(typeKey)
.addKey(degreeKey)
.buildMixedIndex("search");
management.commit();
目标是我可以搜索特定类型的顶点,并使用度对它们进行排序。我相信以下内容应该实现:
graph.traversal().V().has("TYPE", "person").order.by("DEGREE");
然而,上面的遍历显然没有使用索引,因为我收到以下错误:
Could not execute query since pre-sorting requires fetching more than 1000000 elements. Consider rewriting the query to exploit sort orders
奇怪的是,我已经确认弹性搜索可以非常快速地回答我的查询。直接使用以下查询到Elasticsearch:
curl -XGET 'localhost:9200/titan/byTypeDegree/_search?size=80' -d '
{
"sort" : [
{ "DEGREE" : {"order" : "desc"}}
],
"query" : {
"filtered" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : {"TYPE" : "person"}}
]
}
}
}
}
}
我得到了我需要的结果:
"hits": [
"_index": "titan",
"_type": "byTypeDegree",
"_id": "izaqnk",
"_score": null,
"_source": {
"TYPE": "http://mindmaps.io/person",
"DEGREE": 140
},
"sort": [
140
]
},
{
"_index": "titan",
"_type": "byTypeDegree",
"_id": "8j5oxk",
"_score": null,
"_source": {
"TYPE": "http://mindmaps.io/person",
"DEGREE": 112
},
"sort": [
112
]
},
...
那么为什么Titan不能使用索引执行遍历?我是否错误地创建索引或遍历不正确?
关于这个问题的当前问题似乎是关于泰坦0.5.x
,所以一些帮助将不胜感激。
答案 0 :(得分:0)
我已经弄清楚了我的问题。这可能实际上是对泰坦部分的疏忽。我将索引构造修改为:
TitanGraph titanGraph = TitanFactory.open("titan-cassandra-es.properties");
TitanManagement management = graph.openManagement();
PropertyKey typeKey = management.makePropertyKey("TYPE").dataType(String.class).make();
PropertyKey degreeKey = management.makePropertyKey("DEGREE").dataType(Long.class).make();
management.buildIndex("byTypeDegree", Vertex.class)
.addKey(typeKey, Mapping.STRING.asParameter()))
.addKey(degreeKey)
.buildMixedIndex("search");
management.commit();
明确说明typeKey
是Mapping.STRING.asParameter()
我能够执行遍历:
graph.traversal().V().has("TYPE", "person").order.by("DEGREE");
很快。奇怪的是,当想要在索引数值范围上使用order().by()
时,这似乎是一种限制。