簡體   English   中英

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參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM