标签:增加 bool tar trying 报错 iba ons sea utc
es版本7.6。
在使用python操作es执行date_histogram后台报错“elasticsearch.exceptions.TransportError:TransportError(503...”,kibana里执行同样的条件,报“Trying to create too many buckets. Must be less than or equal to: [10000]”。
后来发现是"time_zone"和"extended_bounds"出的问题,time_zone我设置的是东8区,而extended_bounds中的starttime和endtime还是UTC,因此endtime要在8小时之后,时间跨度很大,导致buckets数量超出限制。需要对extended_bounds日期也增加8小时。
es = Elasticsearch([‘127.0.0.1:9200‘], http_auth=(‘elastic‘, ‘elastic‘), timeout=50000) data = { "size": 0, "query": { "bool": { "must": [ { "range": { "@timestamp": { "gte": starttime, # UTC "lte": endtime, # UTC "format": "yyyy-MM-dd HH:mm:ss" } } } ] } }, "aggs": { "group_by_timestamp": { "date_histogram": { "field": "@timestamp", "fixed_interval": ‘1s‘, "format": "yyyy-MM-dd HH:mm:ss", "time_zone": "Asia/Shanghai", # 设置时区为东8区 "min_doc_count": 0, "extended_bounds": { "min": starttime, # 需要增加8小时 + datetime.timedelta(hours=8) "max": endtime # 需要增加8小时 + datetime.timedelta(hours=8) } } } } } es.search(index=[index_name], ignore_unavailable=True, body=data)
python elasticsearch date_histogram聚合查询
标签:增加 bool tar trying 报错 iba ons sea utc
原文地址:https://www.cnblogs.com/zd1009/p/12977779.html