在[过滤器]下预期[START_OBJECT]

时间:2017-12-31 03:22:36

标签: rest elasticsearch

我想在aggs中加入双重过滤器。 像这样。

"aggs": {
  "download1" : {
        "filter" : [
            { "term": { "IPV4_DST_ADDR":"192.168.0.159"}},
            { "range": { "LAST_SWITCHED": { "gte": "now-5m" } }}
        ],
        "aggs" : {
            "downlod_bytes" : { "sum" : { "field" : "IN_BYTES" } }
        }
    }
}

但是它显示了一个错误:

"error": {
"root_cause": [
  {
    "type": "parsing_exception",
    "reason": "Expected [START_OBJECT] under [filter], but got a [START_ARRAY] in [download1]",
    "line": 33,
    "col": 24
  }
]}

我该怎么办,提前谢谢你!

1 个答案:

答案 0 :(得分:1)

您需要将两个查询与bool/filter

组合在一起
{
  "aggs": {
    "download1": {
      "filter": {
        "bool": {
          "filter": [
            {
              "term": {
                "IPV4_DST_ADDR": "192.168.0.159"
              }
            },
            {
              "range": {
                "LAST_SWITCHED": {
                  "gte": "now-5m"
                }
              }
            }
          ]
        }
      },
      "aggs": {
        "downlod_bytes": {
          "sum": {
            "field": "IN_BYTES"
          }
        }
      }
    }
  }
}