diff --git a/docs/build.gradle b/docs/build.gradle
index 1c9a810d6f1b3..4b963248c571f 100644
--- a/docs/build.gradle
+++ b/docs/build.gradle
@@ -24,7 +24,6 @@ apply plugin: 'elasticsearch.docs-test'
  * only remove entries from this list. When it is empty we'll remove it
  * entirely and have a party! There will be cake and everything.... */
 buildRestTests.expectedUnconvertedCandidates = [
-  'reference/aggregations/bucket/iprange-aggregation.asciidoc',
   'reference/aggregations/bucket/nested-aggregation.asciidoc',
   'reference/aggregations/bucket/range-aggregation.asciidoc',
   'reference/aggregations/bucket/reverse-nested-aggregation.asciidoc',
@@ -505,3 +504,42 @@ for (int i = 0; i < 100; i++) {
             {"index":{}}
             {"load_time": "$value"}"""
 }
+
+// Used by iprange agg
+buildRestTests.setups['iprange'] = '''
+  - do:
+        indices.create:
+          index: ip_addresses
+          body:
+            settings:
+              number_of_shards: 1
+              number_of_replicas: 1
+            mappings:
+              data:
+                properties:
+                  ip:
+                    type: ip
+  - do:
+        bulk:
+          index: ip_addresses
+          type: data
+          refresh: true
+          body: |'''
+
+
+for (int i = 0; i < 255; i++) {
+  buildRestTests.setups['iprange'] += """
+            {"index":{}}
+            {"ip": "10.0.0.$i"}"""
+}
+for (int i = 0; i < 5; i++) {
+  buildRestTests.setups['iprange'] += """
+            {"index":{}}
+            {"ip": "9.0.0.$i"}"""
+  buildRestTests.setups['iprange'] += """
+            {"index":{}}
+            {"ip": "11.0.0.$i"}"""
+  buildRestTests.setups['iprange'] += """
+            {"index":{}}
+            {"ip": "12.0.0.$i"}"""
+}
\ No newline at end of file
diff --git a/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc b/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc
index ee77d57a0b476..2f099cc8b2f48 100644
--- a/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc
+++ b/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc
@@ -7,7 +7,9 @@ Example:
 
 [source,js]
 --------------------------------------------------
+GET /ip_addresses/data/_search
 {
+    "size": 10,
     "aggs" : {
         "ip_ranges" : {
             "ip_range" : {
@@ -21,6 +23,8 @@ Example:
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:iprange]
 
 Response:
 
@@ -34,23 +38,26 @@ Response:
             "buckets" : [
                 {
                     "to": "10.0.0.5",
-                    "doc_count": 4
+                    "doc_count": 10
                 },
                 {
                     "from": "10.0.0.5",
-                    "doc_count": 6
+                    "doc_count": 260
                 }
             ]
         }
     }
 }
 --------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
 
 IP ranges can also be defined as CIDR masks:
 
 [source,js]
 --------------------------------------------------
+GET /ip_addresses/data/_search
 {
+    "size": 0,
     "aggs" : {
         "ip_ranges" : {
             "ip_range" : {
@@ -64,32 +71,37 @@ IP ranges can also be defined as CIDR masks:
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:iprange]
 
 Response:
 
 [source,js]
 --------------------------------------------------
 {
+    ...
+
     "aggregations": {
         "ip_ranges": {
             "buckets": [
                 {
                     "key": "10.0.0.0/25",
                     "from": "10.0.0.0",
-                    "to": "10.0.0.127",
-                    "doc_count": 127
+                    "to": "10.0.0.128",
+                    "doc_count": 128
                 },
                 {
                     "key": "10.0.0.127/25",
                     "from": "10.0.0.0",
-                    "to": "10.0.0.127",
-                    "doc_count": 127
+                    "to": "10.0.0.128",
+                    "doc_count": 128
                 }
             ]
         }
     }
 }
 --------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
 
 ==== Keyed Response
 
@@ -97,11 +109,13 @@ Setting the `keyed` flag to `true` will associate a unique string key with each
 
 [source,js]
 --------------------------------------------------
+GET /ip_addresses/data/_search
 {
+    "size": 0,
     "aggs": {
         "ip_ranges": {
             "ip_range": {
-                "field": "remote_ip",
+                "field": "ip",
                 "ranges": [
                     { "to" : "10.0.0.5" },
                     { "from" : "10.0.0.5" }
@@ -112,6 +126,8 @@ Setting the `keyed` flag to `true` will associate a unique string key with each
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:iprange]
 
 Response:
 
@@ -125,27 +141,30 @@ Response:
             "buckets": {
                 "*-10.0.0.5": {
                     "to": "10.0.0.5",
-                    "doc_count": 1462
+                    "doc_count": 10
                 },
                 "10.0.0.5-*": {
                     "from": "10.0.0.5",
-                    "doc_count": 50000
+                    "doc_count": 260
                 }
             }
         }
     }
 }
 --------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
 
 It is also possible to customize the key for each range:
 
 [source,js]
 --------------------------------------------------
+GET /ip_addresses/data/_search
 {
+    "size": 0,
     "aggs": {
         "ip_ranges": {
             "ip_range": {
-                "field": "remote_ip",
+                "field": "ip",
                 "ranges": [
                     { "key": "infinity", "to" : "10.0.0.5" },
                     { "key": "and-beyond", "from" : "10.0.0.5" }
@@ -156,6 +175,8 @@ It is also possible to customize the key for each range:
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:iprange]
 
 Response:
 
@@ -169,14 +190,15 @@ Response:
             "buckets": {
                 "infinity": {
                     "to": "10.0.0.5",
-                    "doc_count": 1462
+                    "doc_count": 10
                 },
                 "and-beyond": {
                     "from": "10.0.0.5",
-                    "doc_count": 50000
+                    "doc_count": 260
                 }
             }
         }
     }
 }
 --------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
\ No newline at end of file