Skip to content

Commit 896afa4

Browse files
committed
CONSOLEify ip-range bucket agg docs
Related #18160
1 parent 19eeb4b commit 896afa4

File tree

2 files changed

+73
-13
lines changed

2 files changed

+73
-13
lines changed

docs/build.gradle

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ apply plugin: 'elasticsearch.docs-test'
2424
* only remove entries from this list. When it is empty we'll remove it
2525
* entirely and have a party! There will be cake and everything.... */
2626
buildRestTests.expectedUnconvertedCandidates = [
27-
'reference/aggregations/bucket/iprange-aggregation.asciidoc',
2827
'reference/aggregations/bucket/nested-aggregation.asciidoc',
2928
'reference/aggregations/bucket/range-aggregation.asciidoc',
3029
'reference/aggregations/bucket/reverse-nested-aggregation.asciidoc',
@@ -505,3 +504,42 @@ for (int i = 0; i < 100; i++) {
505504
{"index":{}}
506505
{"load_time": "$value"}"""
507506
}
507+
508+
// Used by iprange agg
509+
buildRestTests.setups['iprange'] = '''
510+
- do:
511+
indices.create:
512+
index: ip_addresses
513+
body:
514+
settings:
515+
number_of_shards: 1
516+
number_of_replicas: 1
517+
mappings:
518+
data:
519+
properties:
520+
ip:
521+
type: ip
522+
- do:
523+
bulk:
524+
index: ip_addresses
525+
type: data
526+
refresh: true
527+
body: |'''
528+
529+
530+
for (int i = 0; i < 255; i++) {
531+
buildRestTests.setups['iprange'] += """
532+
{"index":{}}
533+
{"ip": "10.0.0.$i"}"""
534+
}
535+
for (int i = 0; i < 5; i++) {
536+
buildRestTests.setups['iprange'] += """
537+
{"index":{}}
538+
{"ip": "9.0.0.$i"}"""
539+
buildRestTests.setups['iprange'] += """
540+
{"index":{}}
541+
{"ip": "11.0.0.$i"}"""
542+
buildRestTests.setups['iprange'] += """
543+
{"index":{}}
544+
{"ip": "12.0.0.$i"}"""
545+
}

docs/reference/aggregations/bucket/iprange-aggregation.asciidoc

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Example:
77

88
[source,js]
99
--------------------------------------------------
10+
GET /ip_addresses/data/_search
1011
{
12+
"size": 10,
1113
"aggs" : {
1214
"ip_ranges" : {
1315
"ip_range" : {
@@ -21,6 +23,8 @@ Example:
2123
}
2224
}
2325
--------------------------------------------------
26+
// CONSOLE
27+
// TEST[setup:iprange]
2428

2529
Response:
2630

@@ -34,23 +38,26 @@ Response:
3438
"buckets" : [
3539
{
3640
"to": "10.0.0.5",
37-
"doc_count": 4
41+
"doc_count": 10
3842
},
3943
{
4044
"from": "10.0.0.5",
41-
"doc_count": 6
45+
"doc_count": 260
4246
}
4347
]
4448
}
4549
}
4650
}
4751
--------------------------------------------------
52+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
4853

4954
IP ranges can also be defined as CIDR masks:
5055

5156
[source,js]
5257
--------------------------------------------------
58+
GET /ip_addresses/data/_search
5359
{
60+
"size": 0,
5461
"aggs" : {
5562
"ip_ranges" : {
5663
"ip_range" : {
@@ -64,44 +71,51 @@ IP ranges can also be defined as CIDR masks:
6471
}
6572
}
6673
--------------------------------------------------
74+
// CONSOLE
75+
// TEST[setup:iprange]
6776

6877
Response:
6978

7079
[source,js]
7180
--------------------------------------------------
7281
{
82+
...
83+
7384
"aggregations": {
7485
"ip_ranges": {
7586
"buckets": [
7687
{
7788
"key": "10.0.0.0/25",
7889
"from": "10.0.0.0",
79-
"to": "10.0.0.127",
80-
"doc_count": 127
90+
"to": "10.0.0.128",
91+
"doc_count": 128
8192
},
8293
{
8394
"key": "10.0.0.127/25",
8495
"from": "10.0.0.0",
85-
"to": "10.0.0.127",
86-
"doc_count": 127
96+
"to": "10.0.0.128",
97+
"doc_count": 128
8798
}
8899
]
89100
}
90101
}
91102
}
92103
--------------------------------------------------
104+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
93105

94106
==== Keyed Response
95107

96108
Setting the `keyed` flag to `true` will associate a unique string key with each bucket and return the ranges as a hash rather than an array:
97109

98110
[source,js]
99111
--------------------------------------------------
112+
GET /ip_addresses/data/_search
100113
{
114+
"size": 0,
101115
"aggs": {
102116
"ip_ranges": {
103117
"ip_range": {
104-
"field": "remote_ip",
118+
"field": "ip",
105119
"ranges": [
106120
{ "to" : "10.0.0.5" },
107121
{ "from" : "10.0.0.5" }
@@ -112,6 +126,8 @@ Setting the `keyed` flag to `true` will associate a unique string key with each
112126
}
113127
}
114128
--------------------------------------------------
129+
// CONSOLE
130+
// TEST[setup:iprange]
115131

116132
Response:
117133

@@ -125,27 +141,30 @@ Response:
125141
"buckets": {
126142
"*-10.0.0.5": {
127143
"to": "10.0.0.5",
128-
"doc_count": 1462
144+
"doc_count": 10
129145
},
130146
"10.0.0.5-*": {
131147
"from": "10.0.0.5",
132-
"doc_count": 50000
148+
"doc_count": 260
133149
}
134150
}
135151
}
136152
}
137153
}
138154
--------------------------------------------------
155+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
139156

140157
It is also possible to customize the key for each range:
141158

142159
[source,js]
143160
--------------------------------------------------
161+
GET /ip_addresses/data/_search
144162
{
163+
"size": 0,
145164
"aggs": {
146165
"ip_ranges": {
147166
"ip_range": {
148-
"field": "remote_ip",
167+
"field": "ip",
149168
"ranges": [
150169
{ "key": "infinity", "to" : "10.0.0.5" },
151170
{ "key": "and-beyond", "from" : "10.0.0.5" }
@@ -156,6 +175,8 @@ It is also possible to customize the key for each range:
156175
}
157176
}
158177
--------------------------------------------------
178+
// CONSOLE
179+
// TEST[setup:iprange]
159180

160181
Response:
161182

@@ -169,14 +190,15 @@ Response:
169190
"buckets": {
170191
"infinity": {
171192
"to": "10.0.0.5",
172-
"doc_count": 1462
193+
"doc_count": 10
173194
},
174195
"and-beyond": {
175196
"from": "10.0.0.5",
176-
"doc_count": 50000
197+
"doc_count": 260
177198
}
178199
}
179200
}
180201
}
181202
}
182203
--------------------------------------------------
204+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]

0 commit comments

Comments
 (0)