gpt4 book ai didi

elasticsearch - 如何在kibana中按条件填充脚本字段值

转载 作者:行者123 更新时间:2023-12-02 23:02:42 28 4
gpt4 key购买 nike

我正在使用Kibana 4,并且我的文档包含两个名为“x”和“y”的整数字段。我想在Kibana中创建一个脚本化字段,如果'y'<> 0,则返回'x'除以'y'的值。否则:返回'x'的值。

我试图将此脚本添加到此处的新screnter代码字段中:
doc['x'].value > 0 ? doc['x'].value/doc['y'].value : doc['x'].value;
但是尝试可视化时出现解析错误:

Error: Request to Elasticsearch failed: {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures



如何在Kibana中逐步创建具有条件的脚本字段?

最佳答案

您所看到的不是解析错误,shardFailures仅表示基础Elasticsearch尚未准备好。启动Kibana / Elasticsearch时,请确保在进入Kibana之前已准备好ES集群,即运行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

请试一试

关于elasticsearch - 如何在kibana中按条件填充脚本字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30275082/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com