---
setup:
  - do:
      indices.create:
        index: sensor
        body:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
          mappings:
            dynamic: false
            runtime:
              host.ip:
                type: ip
            properties:
              timestamp:
                type: date
              temperature:
                type: long
              voltage:
                type: double
              node:
                type: keyword

  - do:
      bulk:
        index: sensor
        refresh: true
        body: |
          {"index":{}}
          {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a", "host" : { "ip" : "128.192.7.1" } }
          {"index":{}}
          {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "host" : [ { "ip" : "1288888.192.7.1" } ] }
          {"index":{}}
          {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "host" : { "ip" : [ "128.192.7.3" ] } }
          {"index":{}}
          {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "host" : { "ip" : "128.192.7.4" } }
          {"index":{}}
          {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "host" : { "ip" : 12819275 } }
          {"index":{}}
          {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "host" : { "ip" : "128.192.7.6" } }

---
"get mapping":
  - do:
      indices.get_mapping:
        index: sensor
  - match: { sensor.mappings.runtime.host\.ip.type: ip }
  - is_false: sensor.mappings.runtime.host\.ip.script

---
"test matching":
  - do:
      search:
        index: sensor
        body:
          query:
            range:
              host.ip:
                gte: "128.192.7.1"
                lte: "128.192.7.5"
  - match: { hits.total.value: 3 }
