2016-08-04 81 views
0

運行代碼,Elasticsearch DSL:鬥不工作

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。我想到了一個條款鬥應該將所有具有相同的退出代碼,在這種情況下的結果。究竟發生了什麼?

回答

1

你遍歷命中,你需要遍歷聚合水桶代替:

response = s.execute() 
for code in response.aggregations.ExitCode.buckets: 
    print(code.key, code.avgCpuEff.value)