Elasticsearch 查询正在刷新所有数据,而不是仅使用 python 搜索术语

Elasticsearch query is flushing all data instead of terms only search with python

我需要查询弹性索引中某个字段的所有值。 当我在 elasticsearch 开发控制台中搜索术语时,我得到了预期的结果:

GET index/_search
{
    "aggs" : {
        "All_IDs" : {
            "terms" : { "field" : "ID", "size":10000 }
        }
    },
    "size" : 0
}

回复:

"aggregations" : {
    "All_IDs" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "XX05215",
          "doc_count" : 4560
        },
        {
          "key" : "XX05216",
          "doc_count" : 3364
        },
        {
          "key" : "E1004903",
          "doc_count" : 2369
        }....

太好了! 但是,当我在 python 中使用 elasticsearch 客户端时,响应包含聚合,但我也从整个数据库中刷新了数据,这开销太大了:

es = Elasticsearch(
    hosts = [{'host': host, 'port': 443},],
    http_auth = awsauth,
    use_ssl = True,
    verify_certs = True,
    connection_class = RequestsHttpConnection
)


query = {
    
        "aggs" : {
            "All_IDs" : {
                "terms" : { "field" : "ID", "size":10000 }
            }
        },
        "size" : 0
    }

response = es.search( index='index', body=query, size=9999 )

如何在 python 中以与在控制台中相同的方式查询并仅检索所需的 ID?

问题出在查询请求中传递的 size 参数,如下面的请求所示。

es.search( index='index', body=query, size=9999 )

删除后,它使用查询正文中传递的 size 参数。