将部分IP与Elasticsearch匹配 [英] Match partial IP with Elasticsearch
本文介绍了将部分IP与Elasticsearch匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在索引中,我有一个IP字段.字段的类型为"ip".
In my index, I have an IP field. The type of the field is "ip".
我要搜索以"192.168"开头的所有IP
I want to search all IPs who starts with "192.168"
我所有的尝试都失败,并显示以下消息:
All my tentative have failed with the following message:
无法解析IP [192.168],不是有效的IP地址
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"?
谢谢.
推荐答案
您可以使用范围查询,例如:
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"
}
}
}
}
这篇关于将部分IP与Elasticsearch匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文