使用 Elasticsearch 匹配部分 IP

Match partial IP with Elasticsearch

在我的索引中,我有一个 IP 字段。字段类型为"ip".

我要搜索所有以“192.168”开头的IP

我的所有尝试都失败了,并显示以下消息:

failed to parse ip [192.168], not a valid ip address

有没有办法做到这一点,或者我应该将字段类型更改为 "string"?

谢谢。

您可以使用范围查询,例如:

GET my_index/_search
{
  "query": {
    "range": {
      "ip_addr": {
        "gte": "192.168.0.0",
        "lt":  "192.168.255.255"
      }
    }
  }
}