Advertisement
Guest User

IP range sample

a guest
Aug 11th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.41 KB | None | 0 0
  1. ## Create test index
  2. curl -XPUT 'http://localhost:9200/ip_test/' -d '{
  3.    "settings" : {
  4.        "index" : {
  5.            "number_of_shards" : 1,
  6.            "number_of_replicas" : 0
  7.        },
  8.        "mappings" : {
  9.        "ip_test" : {
  10.            "properties" : {
  11.                "ip_start" : { "type" : "ip", "index" : "not_analyzed", "doc_values" : false },
  12.                "ip_end" : { "type" : "ip", "index" : "not_analyzed", "doc_values" : false }
  13.            }
  14.        }
  15.      }
  16.    }
  17. }'
  18.  
  19. ## Put range 127.0.0.1 - 127.0.0.255
  20. curl -XPOST 'http://localhost:9200/ip_test/ip_test' -d '{
  21.    ip_start: "127.0.0.1",
  22.    ip_end: "127.0.0.255"
  23. }'
  24.  
  25. ## Put range 10.0.0.1 - 10.0.0.255
  26. curl -XPOST 'http://localhost:9200/ip_test/ip_test' -d '{
  27.    ip_start: "10.0.0.1",
  28.    ip_end: "10.0.0.255"
  29. }'
  30.  
  31. ## Search for IP 127.0.0.1 in ranges
  32. curl -XPOST 'http://localhost:9200/ip_test/_search' -d '{
  33.  "query": {
  34.    "filtered": {
  35.      "filter": [
  36.        {
  37.          "bool": {
  38.            "must": [
  39.              {
  40.                "range": {
  41.                  "ip_start": {
  42.                    "lte": "127.0.0.1"
  43.                  }
  44.                }
  45.              },
  46.              {
  47.                "range": {
  48.                  "ip_end": {
  49.                    "gte": "127.0.0.1"
  50.                  }
  51.                }
  52.              }
  53.            ]
  54.          }
  55.        }
  56.      ]
  57.    }
  58.  }
  59. }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement