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

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

---
"test matching":
  - do:
      search:
        index: sensor
        body:
          query:
            term:
              state.active: false
  - match: { hits.total.value: 2 }
  - do:
      search:
        index: sensor
        body:
          query:
            term:
              state.active: true
  - match: { hits.total.value: 4 }
