iprange-aggregation.asciidoc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. [[search-aggregations-bucket-iprange-aggregation]]
  2. === IPv4 Range Aggregation
  3. Just like the dedicated <<search-aggregations-bucket-daterange-aggregation,date>> range aggregation, there is also a dedicated range aggregation for IPv4 typed fields:
  4. Example:
  5. [source,js]
  6. --------------------------------------------------
  7. {
  8. "aggs" : {
  9. "ip_ranges" : {
  10. "ip_range" : {
  11. "field" : "ip",
  12. "ranges" : [
  13. { "to" : "10.0.0.5" },
  14. { "from" : "10.0.0.5" }
  15. ]
  16. }
  17. }
  18. }
  19. }
  20. --------------------------------------------------
  21. Response:
  22. [source,js]
  23. --------------------------------------------------
  24. {
  25. ...
  26. "aggregations": {
  27. "ip_ranges": {
  28. "buckets" : [
  29. {
  30. "to": 167772165,
  31. "to_as_string": "10.0.0.5",
  32. "doc_count": 4
  33. },
  34. {
  35. "from": 167772165,
  36. "from_as_string": "10.0.0.5",
  37. "doc_count": 6
  38. }
  39. ]
  40. }
  41. }
  42. }
  43. --------------------------------------------------
  44. IP ranges can also be defined as CIDR masks:
  45. [source,js]
  46. --------------------------------------------------
  47. {
  48. "aggs" : {
  49. "ip_ranges" : {
  50. "ip_range" : {
  51. "field" : "ip",
  52. "ranges" : [
  53. { "mask" : "10.0.0.0/25" },
  54. { "mask" : "10.0.0.127/25" }
  55. ]
  56. }
  57. }
  58. }
  59. }
  60. --------------------------------------------------
  61. Response:
  62. [source,js]
  63. --------------------------------------------------
  64. {
  65. "aggregations": {
  66. "ip_ranges": {
  67. "buckets": [
  68. {
  69. "key": "10.0.0.0/25",
  70. "from": 1.6777216E+8,
  71. "from_as_string": "10.0.0.0",
  72. "to": 167772287,
  73. "to_as_string": "10.0.0.127",
  74. "doc_count": 127
  75. },
  76. {
  77. "key": "10.0.0.127/25",
  78. "from": 1.6777216E+8,
  79. "from_as_string": "10.0.0.0",
  80. "to": 167772287,
  81. "to_as_string": "10.0.0.127",
  82. "doc_count": 127
  83. }
  84. ]
  85. }
  86. }
  87. }
  88. --------------------------------------------------