运行代码,
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q, A
client = Elasticsearch(timeout=100)
s = Search(using=client, index="cms*")
s.aggs.bucket('ExitCode', 'terms', field='ExitCode').metric('avgCpuEff', 'avg', field='CpuEff')
for hit in s[0:20].execute():
print hit['ExitCode']
产生几个ExitCode =0。在这种情况下,我认为条件存储区应该将所有具有相同退出代码的结果归为一组。实际发生了什么?
最佳答案
您要遍历匹配数,而需要遍历聚合的存储桶:
response = s.execute()
for code in response.aggregations.ExitCode.buckets:
print(code.key, code.avgCpuEff.value)