当使用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
奇怪的是,我已经确认 flex 搜索可以非常快速地回答我的查询。直接使用以下查询到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
有关,因此将不胜感激。
最佳答案
我已经解决了我的问题。实际上这可能是Titan的疏忽。我将索引结构修改为:
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()
时,这似乎是一个限制。
关于elasticsearch - 使用Elasticsearch在Titan上进行有序遍历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358643/