gpt4 book ai didi

elasticsearch - 如何在 Elasticsearch 中查询IP范围?

转载 作者:行者123 更新时间:2023-12-02 22:17:57 25 4
gpt4 key购买 nike

我想在ELK中查询IP范围从:172.16.0.0到172.31.0.0
我尝试了两种查询方法,但是失败了。

{
"query": {
"bool": {
"should": [
{
"regexp": {
"DstIP": "172.(3[0-1]|1[6-9]|2[0-9]).*"
}
}
],
"minimum_should_match": 1
}
}
}
{
"query": {
"range": {
"DstIP": {
"gte": "172.16.0.0",
"lte": "172.31.0.0"
}
}
}
}
如何在ELK中查询IP范围?

最佳答案

为了使范围查询能够正确处理IP值,必须将字段数据类型定义为ip
以下是包含映射,示例文档和搜索查询的工作示例。
索引映射:

{
"mappings": {
"properties": {
"dest": {
"type": "ip"
}
}
}
}
索引样本数据:
然后,我采取了一些示例文档,如下所示:
{ "dest":"172.16.0.0"}
{ "dest":"172.31.0.0"}
{ "dest":"172.21.0.0"}
{ "dest":"172.1.0.0" }
{ "dest":"172.12.0.0"}
搜索查询:
{
"query": {
"range": {
"dest": {
"gte": "172.16.0.0",
"lte": "172.31.0.0"
}
}
}
}
搜索结果:
 "hits": [
{
"_index": "foo4",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"dest": "172.16.0.0"
}
},
{
"_index": "foo4",
"_type": "_doc",
"_id": "2",
"_score": 1.0,
"_source": {
"dest": "172.31.0.0"
}
},
{
"_index": "foo4",
"_type": "_doc",
"_id": "3",
"_score": 1.0,
"_source": {
"dest": "172.21.0.0"
}
}
]

关于elasticsearch - 如何在 Elasticsearch 中查询IP范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62506849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com