elasticsearch.exceptions.TransportError:TransportError 503:数据太大

时间:2018-04-16 07:41:30

标签: python elasticsearch

我试图让ES的响应从python代码中获取,但它显示以下错误:

elasticsearch.exceptions.TransportError: TransportError(503, u'search_phase_execution_exception', u'[request] Data too large, data for [<agg [POSCodeModifier]>] would be [623327280/594.4mb], which is larger than the limit of [623326003/594.4mb]')

如果我从kibana点击相同的代码,我得到的结果,但使用python我得到这个错误。我在我的代码中使用聚合。如果有人可以解释我是否需要设置一些属性或如何优化它? 以下是请求发送的结构,如果我将开始和结束日期设置为大于5天,则会给出错误,否则我会得到结果

unmtchd_ESdata= es.search(index='cstore_new',body={'size' : 0, "aggs": {
    "filtered": {
      "filter": {
        "bool": {
          "must_not": [
            {
              "match": {
                "CSPAccountNo": store_id
              }
            }
          ],
          "must": [
            {
              "range": {
                "ReportDate": {
                  "gte": start_dt,
                  "lte": end_dt
                }
              }
            }
          ]
        }
      }
    ,
    "aggs": {
      "POSCode": {
        "terms": {
          "field": "POSCode",
          "size": 10000
        },
        "aggs": {
          "POSCodeModifier": {
            "terms": {
              "field": "POSCodeModifier",
              "size": 10000
            },
            "aggs": {
              "CSP": {
                "terms": {
                  "field": "CSPAccountNo",
                  "size": 10000
                },
                "aggs": {
                  "per_stock": {
                    "date_histogram": {
                      "field": "ReportDate",
                      "interval": "week",
                      "format": "yyyy-MM-dd",
                      "min_doc_count": 0,
                      "extended_bounds": {
                        "min": start_dt,
                        "max": end_dt
                      }
                    },
                    "aggs": {
                      "avg_week_qty_sales": {
                        "sum": {
                          "field": "TotalCount"
                        }
                      }
                    }
                  },
                  "market_week_metrics": {
                    "extended_stats_bucket": {
                      "buckets_path": "per_stock>avg_week_qty_sales"
                    }
                  }
                }
              }
            }

          }
        }
      }
    }
  }
}},request_timeout=1000)

EDIT1: 弹性搜索响应所需的结果变量

for i in range(len(unmtchd_ESdata['aggregations']['filtered']['POSCode']['buckets'])):
            list6.append(unmtchd_ESdata['aggregations']['filtered']['POSCode']['buckets'][i]['POSCodeModifier']['buckets'][0]['CSP']['buckets'][0]['market_week_metrics']['avg'])
            list7.append(unmtchd_ESdata['aggregations']['filtered']['POSCode']['buckets'][i]['key'])
            list8.append(unmtchd_ESdata['aggregations']['filtered']['POSCode']['buckets'][i]['POSCodeModifier']['buckets'][0]['CSP']['buckets'][0]['market_week_metrics']['max']-unmtchd_ESdata['aggregations']['filtered']['POSCode']['buckets'][i]['POSCodeModifier']['buckets'][0]['CSP']['buckets'][0]['market_week_metrics']['min'])
            list9.append(unmtchd_ESdata['aggregations']['filtered']['POSCode']['buckets'][i]['POSCodeModifier']['buckets'][0]['CSP']['buckets'][0]['market_week_metrics']['max'])
            list10.append(unmtchd_ESdata['aggregations']['filtered']['POSCode']['buckets'][i]['POSCodeModifier']['buckets'][0]['CSP']['buckets'][0]['market_week_metrics']['min'])

0 个答案:

没有答案