Elasticsearch DSL:Bucket无法正常工作(Elasticsearch DSL: Bucket not working)

系统教程 行业动态 更新时间:2024-06-14 16:59:46
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)

更多推荐

本文发布于:2023-04-17 08:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/bbace55b488dc80fd084e1ab8bc53ddd.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   DSL   Elasticsearch   working

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!