---
setup:
  - do:
      indices.create:
        index: products
        body:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
          mappings:
            properties:
              name:
                type: keyword
              resellers:
                type: nested
                properties:
                  reseller:
                    type: keyword

  - do:
      bulk:
        index: products
        refresh: true
        body: |
          {"index":{}}
          {"name":"LED TV","resellers":[{"reseller":"companyA","price":350},{"reseller":"companyB","price":500}]}

---
"test docvalue loading":
  - do:
      search:
        index: products
        body:
          runtime_mappings:
            "resellers.price_with_vat":
              type: double
              script: |
                for (double v : doc['resellers.price']) {
                  emit(v * 1.2)
                }
          query:
            match:
              name: "LED TV"
          aggs:
            resellers:
              nested:
                path: resellers
              aggs:
                min_price:
                  min:
                    field: resellers.price_with_vat

  - match: { aggregations.resellers.doc_count: 2 }
  - match: { aggregations.resellers.min_price.value: 420 }

