【发布时间】:2016-07-21 09:31:27
【问题描述】:
当使用 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 不能使用索引执行遍历呢?是我错误地创建了索引还是遍历不正确?
当前有关此问题的问题似乎与 Titan 0.5.x 有关,因此我们将不胜感激。
【问题讨论】:
-
请注意:您是在 Titan 中创建 byTypeAndDegree 并在 elastic 中查询 byTypeDegree ?它们不应该是同一个字符串吗?
-
输入错误。现在修好了。谢谢@Niloct。
-
应该将
DEGREE声明为数字数据类型而不是String.class? -
另一个输入错误。谢谢@JasonPlurad。
标签: elasticsearch titan