我需要查詢彈性索引中某個欄位的所有值。當我在 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?
uj5u.com熱心網友回復:
問題size在于查詢請求中傳遞的引數,如下面的請求所示。
es.search( index='index', body=query, size=9999 )
洗掉后,它使用size在查詢正文中傳遞的引數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/446603.html
