我需要查询弹性索引中某个字段的所有值.
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
}....
太好了!
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?