Elasticsearch匹配多个IP子网DSL查询

Elasticsearch match multiple IP subnets DSL Query

我正在尝试在 Kibana 中为特定 URI 执行 DSL 查询过滤器,同时匹配多个 IP 子网。 到目前为止,我已经设法让它只与一个 IP 子网一起工作:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "uripath": "/specific-uri-path"
          }
        },
        {
          "match": {
            "clientip": "10.0.0.0/8"
          }
        }
      ]
    }
  }
}

但是如果我尝试匹配多个子网,它会失败(可能是因为匹配只能包含不同的字段):

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "uripath": "/specific-uri-path"
          }
        },
        {
          "match": {
            "clientip": "10.0.0.0/8",
          "match": {
            "clientip": "14.0.0.0/8"
          }
        }
      ]
    }
  }
}

我能够使其与条款查询一起使用。这意味着我还可以为 "clientip" 使用一个值数组,因此总体而言它更简洁。我希望它也能帮助其他人。

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
        "uripath.keyword": "/specific-uri-path"
      }
    },
    {
      "terms": {
        "clientip": [
          "10.0.0.0/8",
          "14.0.0.0/8",
          "20.0.0.0/8"
        ]
      }
    }
   ]
  }
 }
}