Elasticsearch DSL:Bucket无法正常工作(Elasticsearch DSL: Bucket not working)
运行代码,
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.我认为一个术语桶应该对所有具有相同退出代码的结果进行分组,在这种情况下。 究竟发生了什么?
Running the code,
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']yields several ExitCode = 0. I thought a terms bucket is supposed to group all the results that have the same exit code, in this case. What is actually going on?
最满意答案
您正在迭代命中,您需要迭代聚合的桶:
response = s.execute() for code in response.aggregations.ExitCode.buckets: print(code.key, code.avgCpuEff.value)You're iterating over the hits, you need to iterate over the aggregated buckets instead:
response = s.execute() for code in response.aggregations.ExitCode.buckets: print(code.key, code.avgCpuEff.value)更多推荐
发布评论