Match partial IP with Elasticsearch

杀马特。学长 韩版系。学妹 提交于 2019-12-13 17:53:21

问题


In my index, I have an IP field. The type of the field is "ip".

I want to search all IPs who starts with "192.168"

All my tentative have failed with the following message:

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

Is there a way of doing this or should I change the type of the field to "string"?

Thanks.


回答1:


You can use range query for example like:

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


来源:https://stackoverflow.com/questions/37057919/match-partial-ip-with-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!