Elasticsearch polymerization in a polymerization Ip Range IP address range

With respect to the range and date range, the polymerization is capable of representing the IP range.

Normal IP mode

DSL command:

{
    "aggs":{
        "ip_ranges":{
            "ip_range":{
                "field":"ip",
                "ranges":[
                    {"to":"10.0.0.5"},
                    {"from":"10.0.0.5"}
                ]
            }
        }
    }
}

Return result:

{
...
"aggregations":{
    "ip_ranges":{
        "buckets":[
            {
                "to":167772165,
                "to_as_string":"10.0.0.5",
                "doc_count":4
            },{
                "from":167772165,
                "from_as_string":"10.0.0.5",
                "doc_count":6
            }
        ]
        }
    }
}

Mask mode

command:

{
    "aggs":{
        "ip_ranges":{
            "ip_range":{
                "field":"ip",
                "ranges":[
                    {"mask":"10.0.0.0/25"},
                    {"mask":"10.0.0.127/25"}
                ]
            }
        }
    }
}

return

{
    "aggregations":{
        "ip_ranges":{
            "buckets":[
                {
                    "key":"10.0.0.0/25",
                    "from":1.6777216E+8,
                    "from_as_string":"10.0.0.0",
                    "to":167772287,
                    "to_as_string":"10.0.0.127",
                    "doc_count":127
                },{
                    "key":"10.0.0.127/25",
                    "from":1.6777216E+8,
                    "from_as_string":"10.0.0.0",
                    "to":167772287,
                    "to_as_string":"10.0.0.127",
                    "doc_count":127
                }
            ]
        }
    }
}

 

Reproduced in: https: //my.oschina.net/u/204616/blog/544973

Guess you like

Origin blog.csdn.net/weixin_34090562/article/details/91990206