【问题标题】:how to fill a scripted field value by condition in kibana如何在kibana中按条件填充脚本字段值
【发布时间】:2015-05-16 11:28:44
【问题描述】:
我正在使用 Kibana 4,我的文档包含两个整数字段:“x”和“y”。我想在 Kibana 中创建一个脚本字段,如果 'y' 0,则返回 'x' 除以 'y' 的值。否则:返回 'x' 的值。
我已尝试将此脚本添加到新的 screnter 代码字段中:
doc['x'].value > 0 ? doc['x'].value/doc['y'].value : doc['x'].value;
但在尝试将其可视化时出现解析错误:
错误:对 Elasticsearch 的请求失败:
{"error":"SearchPhaseExecutionException[执行阶段[查询]失败,
所有分片失败;分片失败
如何在 Kibana 中逐步创建具有条件的脚本字段?
【问题讨论】:
标签:
elasticsearch
kibana
kibana-4
【解决方案1】:
你看到的不是解析错误,shardFailures 只是表示底层的 Elasticsearch 还没有准备好。启动 Kibana/Elasticsearch 时,请确保您的 ES 集群在进入 Kibana 之前已准备就绪,即运行 curl -XGET localhost:9200/_cluster/health,在响应中,您应该会看到类似以下内容:
{
cluster_name: your_cluster_name
status: yellow <----- this must be either yellow or green
timed_out: false
number_of_nodes: 2
number_of_data_nodes: 2
active_primary_shards: 227
active_shards: 454
relocating_shards: 0 <----- this must be 0
initializing_shards: 0 <----- this must be 0
unassigned_shards: 25
}
至于你的脚本,它是正确编写的,但是你提到的条件不正确,因为你想要y <> 0而不是x > 0,所以应该是
doc['y'].value != 0 ? doc['x'].value / doc['y'].value : doc['x'].value
请试一试