【问题标题】:How to return only aggregation results not hits in elasticsearch query dsl如何在elasticsearch查询dsl中只返回聚合结果而不是命中
【发布时间】:2018-04-15 22:55:35
【问题描述】:

我正在使用http://elasticsearch-dsl.readthedocs.io在python中编写查询dsl

我有以下代码

search.aggs.bucket('per_ts', 'terms', field='ts')\
            .bucket('load_time', 'percentiles', field='total_req', percents=[99])


response = search.execute()

这工作正常,但它也返回hits。但我不想要hits

在 curl 查询模式下,我可以通过 size:0 in 得到我想要的

GET /twitter/tweet/_search
{
  "size": 0,
  "aggregations": {
    "my_agg": {
      "terms": {
        "field": "text"
      }
    }
  }
}

我找不到可以在查询 dsl 中使用 size = 0 的方法。

【问题讨论】:

    标签: python elasticsearch elasticsearch-5


    【解决方案1】:

    参考elasticsearch-dsl-py/search.py​​here的代码

    s = Search().query(...).extra(from_=0, size=25)
    

    这个语句应该有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-14
      • 2018-04-23
      • 2022-09-27
      • 2014-10-22
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多