---
setup:
  - do:
      indices.create:
        index: sensor
        body:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
          mappings:
            dynamic: false
            runtime:
              history.count:
                type: double
            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", "history" : { "count" : 10 } }
          {"index":{}}
          {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "history" : { "count" : [ 11.2 ] } }
          {"index":{}}
          {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "history" : [ { "count" : 12 }, "false", true ] }
          {"index":{}}
          {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "history" : { } }
          {"index":{}}
          {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "history" : { "count" : [ 14.5, true, "manglewurzle" ] } }
          {"index":{}}
          {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "history" : { "count" : 20 } }

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

---
"test matching":
  - do:
      search:
        index: sensor
        body:
          query:
            range:
              history.count:
                gte: 10
                lte: 18
  - match: { hits.total.value: 4 }
