0

I have stored a field that is an array of strings: ["name1","name2",...]

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 here.

doc["mentioning"].values.length

However, when I try to create a visualisation based on this scripted field I get the error message:

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

What am I doing wrong here?

Community
  • 1
  • 1
mattiasostmar
  • 2,869
  • 4
  • 17
  • 26

1 Answers1

0

If you look in your elastic search logs, you will see that the only scriptable field data allowed right now is .value.

Something like:

Caused by: org.elasticsearch.script.expression.ExpressionScriptCompilationException: Invalid member for field data in expression. Only '.value' is currently supported.

So the answer is you cannot access .values.

mooreds
  • 4,932
  • 2
  • 32
  • 40