elasticsearch - 使用Elasticsearch在Titan上进行有序遍历

标签 elasticsearch titan

当使用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(); 

通过明确声明typeKeyMapping.STRING.asParameter(),我能够执行遍历:
graph.traversal().V().has("TYPE", "person").order.by("DEGREE");

很快奇怪的是,当要在索引数字范围上使用order().by()时,这似乎是一个限制。

关于elasticsearch - 使用Elasticsearch在Titan上进行有序遍历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358643/

相关文章:

python - RexProScriptException 事务未在带有 Titan(图形数据库)的 Django 中打开

hadoop - Titan Hadoop-Gremlin 配置问题

java.lang.IllegalStateException : failed to create a child event loop

elasticsearch - 在多节点集群中,elasticsearch.yml 将应用于哪个节点?

graph - 泰坦图: Finding vertices without outgoing edges

elasticsearch - Titan 1.0 [Berkeley + ES]-ES索引的更新延迟

java - 详细 Rexster 输出/记录错误 `null`

rest - 触发河流更新elasticsearch

java - Elasticsearch 5 : MapperParserException with multi_field

elasticsearch - 如何获得一对字段值的计数?