【问题标题】:Pagination with Elastic Search in Titan在 Titan 中使用弹性搜索进行分页
【发布时间】:2023-09-22 22:07:01
【问题描述】:

我在 Titan 中使用 Elastic Search。如何在 ES 中使用 Titan 进行分页?

我看到了THIS,所以正在尝试这个:

Iterable<Result<Vertex>> vertices = g.indexQuery("search","v.testTitle:(mytext)")
            .addParameter(new Parameter("from", 0))
            .addParameter(new Parameter("size", 2)).vertices();    

for (Result<Vertex> result : vertices) {
    Vertex tv = result.getElement();
    System.out.println(tv.getProperty("testTitle")+ ": " + result.getScore());
}

问题是它返回所有 4-5 条记录,而不是 2 的大小

【问题讨论】:

    标签: elasticsearch titan


    【解决方案1】:

    参数尚不支持。该方法仅存在于未来的实现中。 但是,您目前可以限制您的结果。以下代码应该可以工作:

    Iterable<Result<Vertex>> vertices = g.indexQuery("search","v.testTitle:(mytext)")
                .limit(2).vertices();    
    
    for (Result<Vertex> result : vertices) {
        Vertex tv = result.getElement();
        System.out.println(tv.getProperty("testTitle")+ ": " + result.getScore());
    }
    

    ...但您不能指定偏移量。

    干杯, 丹尼尔

    【讨论】:

    • 但这不是分页。想象一个网页,我在其中显示每页 10 条记录的搜索结果。我将如何获得 NEXT 和 PREVIOUS 记录?
    • 正如我所说,目前不支持。您必须找到解决方法或自行实施并发送拉取请求。
    • 你能告诉我如何直接从 ES java 客户端执行相同的查询。我正在关注 elasticsearch.org/guide/en/elasticsearch/client/java-api/0.90/… 这段代码,但它获取了 0 条记录。可能是我设置或丢失了错误的参数。我做了client.prepareSearch("titan").setQuery(QueryBuilders.fieldQuery("offerTitle", "mytext")) 它返回 0 次点击
    【解决方案2】:

    我对titan一无所知。但是要在Elasticsearch中实现分页概念,您可以使用滚动概念。它会很有帮助,它就像db cursor..它可以大大减少CPU使用率。

    参考http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html

    【讨论】:

      最近更新 更多