title: How do I create a scripted field in Kibana that calculates length of an array of strings?
body: <p>I have stored a field that is an array of strings: 
  ["name1","name2",...]</p>
  
  <p>I want to create a scripted field in Kibana 4 that returns the length of that array for each document and tried this script based on what I found <a href="https://stackoverflow.com/questions/12733351/how-do-i-sort-the-search-results-according-to-the-number-of-items-in-elasticsear/12734613#12734613">here</a>.</p>
  
  <pre><code>doc["mentioning"].values.length
  </code></pre>
  
  <p>However, when I try to create a visualisation based on this scripted field I get the error message:</p>
  
  <pre><code>Request to Elasticsearch failed: {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[xUmdnDgoQuKF4KQVNj4R6g][usertexts][0]: SearchParseException[[usertexts][0]: query[ConstantScore(*:*)],from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"aggs\":{\"2\":{\"histogram\":{\"script\":\"doc[\\\"mentioning\\\"].values.length\",\"lang\":\"expression\",\"interval\":10}}}}]]]; nested: ExpressionScriptCompilationException[Invalid member for field data in expression.  Only '.value' is currently supported.]; }{[xUmdnDgoQuKF4KQVNj4R6g][usertexts][1]: SearchParseException[[usertexts][1]: query[ConstantScore(*:*)],from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"aggs\":{\"2\":{\"histogram\":{\"script\":\"doc[\\\"mentioning\\\"].values.length\",\"lang\":\"expression\",\"interval\":10}}}}]]]; nested: ExpressionScriptCompilationException[Invalid member for field data in expression.  Only '.value' is currently supported.]; }{[xUmdnDgoQuKF4KQVNj4R6g][usertexts][2]: SearchParseException[[usertexts][2]: query[ConstantScore(*:*)],from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"aggs\":{\"2\":{\"histogram\":{\"script\":\"doc[\\\"mentioning\\\"].values.length\",\"lang\":\"expression\",\"interval\":10}}}}]]]; nested: ExpressionScriptCompilationException[Invalid member for field data in expression.  Only '.value' is currently supported.]; }{[xUmdnDgoQuKF4KQVNj4R6g][usertexts][3]: SearchParseException[[usertexts][3]: query[ConstantScore(*:*)],from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"aggs\":{\"2\":{\"histogram\":{\"script\":\"doc[\\\"mentioning\\\"].values.length\",\"lang\":\"expression\",\"interval\":10}}}}]]]; nested: ExpressionScriptCompilationException[Invalid member for field data in expression.  Only '.value' is currently supported.]; }{[xUmdnDgoQuKF4KQVNj4R6g][usertexts][4]: SearchParseException[[usertexts][4]: query[ConstantScore(*:*)],from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"aggs\":{\"2\":{\"histogram\":{\"script\":\"doc[\\\"mentioning\\\"].values.length\",\"lang\":\"expression\",\"interval\":10}}}}]]]; nested: ExpressionScriptCompilationException[Invalid member for field data in expression.  Only '.value' is currently supported.]; }]"}KbnError@http://localhost:5601/index.js?_b=5930:39210:30
  RequestFailure@http://localhost:5601/index.js?_b=5930:39247:18
  http://localhost:5601/index.js?_b=5930:42978:56
  try@http://localhost:5601/index.js?_b=5930:46205:31
  http://localhost:5601/index.js?_b=5930:46183:27
  map@[native code]
  map@http://localhost:5601/index.js?_b=5930:46182:33
  callResponseHandlers@http://localhost:5601/index.js?_b=5930:42950:25
  http://localhost:5601/index.js?_b=5930:43068:36
  wrappedCallback@http://localhost:5601/index.js?_b=5930:20873:81
  wrappedCallback@http://localhost:5601/index.js?_b=5930:20873:81
  http://localhost:5601/index.js?_b=5930:20959:34
  $eval@http://localhost:5601/index.js?_b=5930:22002:28
  $digest@http://localhost:5601/index.js?_b=5930:21814:36
  $apply@http://localhost:5601/index.js?_b=5930:22106:31
  done@http://localhost:5601/index.js?_b=5930:17641:51
  completeRequest@http://localhost:5601/index.js?_b=5930:17855:15
  onreadystatechange@http://localhost:5601/index.js?_b=5930:17794:26
  </code></pre>
  
  <p>What am I doing wrong here?</p>