2013-11-24 06:13:08 -05:00
[[search-aggregations-bucket-iprange-aggregation]]
2016-04-18 10:11:11 -04:00
=== IP Range Aggregation
2013-11-24 06:13:08 -05:00
2016-04-18 10:11:11 -04:00
Just like the dedicated <<search-aggregations-bucket-daterange-aggregation,date>> range aggregation, there is also a dedicated range aggregation for IP typed fields:
2013-11-24 06:13:08 -05:00
Example:
[source,js]
--------------------------------------------------
{
"aggs" : {
"ip_ranges" : {
"ip_range" : {
"field" : "ip",
"ranges" : [
{ "to" : "10.0.0.5" },
{ "from" : "10.0.0.5" }
]
}
}
}
}
--------------------------------------------------
Response:
[source,js]
--------------------------------------------------
{
...
"aggregations": {
2015-02-21 03:42:37 -05:00
"ip_ranges": {
2014-01-28 11:46:26 -05:00
"buckets" : [
{
2016-04-18 10:11:11 -04:00
"to": "10.0.0.5",
2014-01-28 11:46:26 -05:00
"doc_count": 4
},
{
2016-04-18 10:11:11 -04:00
"from": "10.0.0.5",
2014-01-28 11:46:26 -05:00
"doc_count": 6
}
]
}
2013-11-24 06:13:08 -05:00
}
}
--------------------------------------------------
IP ranges can also be defined as CIDR masks:
[source,js]
--------------------------------------------------
{
"aggs" : {
"ip_ranges" : {
"ip_range" : {
"field" : "ip",
"ranges" : [
{ "mask" : "10.0.0.0/25" },
{ "mask" : "10.0.0.127/25" }
]
}
}
}
}
--------------------------------------------------
Response:
[source,js]
--------------------------------------------------
{
"aggregations": {
2014-01-28 11:46:26 -05:00
"ip_ranges": {
"buckets": [
{
"key": "10.0.0.0/25",
2016-04-18 10:11:11 -04:00
"from": "10.0.0.0",
"to": "10.0.0.127",
2014-01-28 11:46:26 -05:00
"doc_count": 127
},
{
"key": "10.0.0.127/25",
2016-04-18 10:11:11 -04:00
"from": "10.0.0.0",
"to": "10.0.0.127",
2014-01-28 11:46:26 -05:00
"doc_count": 127
}
]
}
2013-11-24 06:13:08 -05:00
}
}
2016-04-18 10:11:11 -04:00
--------------------------------------------------