如何在Kibana中创建一个脚本字段来计算字符串数组的长度?

时间:2015-06-08 12:50:10

标签: elasticsearch lucene kibana-4

我存储了一个字符串数组的字段: [ “NAME1”, “NAME2”,...]

我想在Kibana 4中创建一个脚本化字段,它返回每个文档的数组长度,并根据我找到的here尝试此脚本。

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

但是,当我尝试基于此脚本字段创建可视化时,我收到错误消息:

public class ColorChooser extends JFrame implements ActionListener
{  
    private JRadioButton bt1;
...
}

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

如果您查看弹性搜索日志,您会看到现在唯一允许的可编写脚本的字段数据是.value

类似的东西:

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

所以答案是你无法访问.values