title: Kibana scripted field which loops through an array
body: <p>I am trying to use the metricbeat http module to monitor F5 pools.</p>
  
  <p>I make a request to the f5 api and bring back json, which is saved to kibana. But the json contains an array of pool members and I want to count the number which are up.</p>
  
  <p>The advice seems to be that this can be done with a scripted field. However, I can't get the script to retrieve the array. eg</p>
  
  <pre><code>doc['http.f5pools.items.monitor'].value.length()
  </code></pre>
  
  <p>returns in the preview results with the same 'Additional Field' added for comparison:</p>
  
  <pre><code>[
   {
    "_id": "rT7wdGsBXQSGm_pQoH6Y",
    "http": {
     "f5pools": {
      "items": [
       {
        "monitor": "default"
       },
       {
        "monitor": "default"
       }
      ]
     }
    },
    "pool.MemberCount": [
     7
    ]
   },
  </code></pre>
  
  <p>If I try</p>
  
  <pre><code>doc['http.f5pools.items']
  </code></pre>
  
  <p>Or similar I just get an error:</p>
  
  <pre><code>"reason": "No field found for [http.f5pools.items] in mapping with types []"
  </code></pre>
  
  <p>Googling suggests that the doc construct does not contain arrays?</p>
  
  <ol>
  <li>Is it possible to make a scripted field which can access the set of values? ie is my code or the way I'm indexing the data wrong.</li>
  <li>If not is there an alternative approach within metricbeats? I don't want to have to make a whole new api to do the calculation and add a separate field</li>
  </ol>
  
  <p>-- update.</p>
  
  <p>Weirdly it seems that the number values in the array do return the expected results. ie.</p>
  
  <pre><code>doc['http.f5pools.items.ratio']
  </code></pre>
  
  <p>returns</p>
  
  <pre><code> {
    "_id": "BT6WdWsBXQSGm_pQBbCa",
    "pool.MemberCount": [
     1,
     1
    ]
   },
  </code></pre>
  
  <p>-- update 2</p>
  
  <p>Ok, so if the strings in the field have different values then you get all the values. if they are the same you just get one. wtf?</p>