【问题标题】:Get all results of elasticsearch without pagination无需分页即可获取elasticsearch的所有结果
【发布时间】:2015-05-10 06:07:13
【问题描述】:

Elastic-search 有from/size 参数,这个size 默认是10。如何在不分页的情况下得到所有结果?

【问题讨论】:

标签: elasticsearch pagination


【解决方案1】:

首先获取结果计数。你可以通过count api得到它。将 n 放入 QueryBuilder 的以下方法中。

CountResponse response = client.prepareCount("test")
    .setQuery(termQuery("_type", "type1"))
    .execute()
    .actionGet();

然后调用

n=response.getCount();

你可以使用 setSize(n)。

对于非 java 使用,像这个 curl 请求。

curl -XGET 'http://localhost:9200/twitter/tweet/_count' -d '
{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}'

可以在此链接上找到更多信息。 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html

【讨论】:

  • 你是对的,但必须有一个像size=allsize=none这样的单步解决方案。
  • 我还没遇到过这种情况。
猜你喜欢
  • 1970-01-01
  • 2022-01-22
  • 2021-11-21
  • 2011-10-05
  • 1970-01-01
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多