Elasticsearch 截断查询中的字符串字段
Elasticsearch truncate string field in query
为了在 Grafana 仪表板上显示最近的异常,我正在查询日志文件中的异常。 Grafana 似乎没有在 table 视图中限制字符串值的选项。当然堆栈跟踪是巨大的。
所以我想到了在使用的 Lucene 查询中限制此字段的想法,但我不知道如何执行此操作。我尝试使用无痛脚本执行此操作:
{
"query": {
"match_all": {}
},
"script_fields": {
"message_short": {
"script": {
"lang": "painless",
"inline": "return doc['message'].value.substring(50);"
}
}
}
}
我没有收到任何错误,但也没有收到我期望的其他字段 "message_short"。我是否必须以某种方式启用脚本支持?我 运行 v6.1.2
我实施了一个解决方法,其中我有一个向下钻取 URL(在 Grafana "Render value as link" 中 Table),我在其中将 link 渲染到我的 Kibana 实例并使用Grafana 变量 $__cell
引用了我从底层 Elasticsearch 查询中得到的 document_id:
https://mykibana.host/app/kibana#/doc/myindex-*/myindex-prod-*/logs?id=$__cell&_g=h@8b5b71a
不完美,但让我的仪表板保持可读性,并在需要时提供更多信息。更好的办法是在 ES 索引中添加一个短路字段,但目前我无法做到这一点。
为了在 Grafana 仪表板上显示最近的异常,我正在查询日志文件中的异常。 Grafana 似乎没有在 table 视图中限制字符串值的选项。当然堆栈跟踪是巨大的。
所以我想到了在使用的 Lucene 查询中限制此字段的想法,但我不知道如何执行此操作。我尝试使用无痛脚本执行此操作:
{
"query": {
"match_all": {}
},
"script_fields": {
"message_short": {
"script": {
"lang": "painless",
"inline": "return doc['message'].value.substring(50);"
}
}
}
}
我没有收到任何错误,但也没有收到我期望的其他字段 "message_short"。我是否必须以某种方式启用脚本支持?我 运行 v6.1.2
我实施了一个解决方法,其中我有一个向下钻取 URL(在 Grafana "Render value as link" 中 Table),我在其中将 link 渲染到我的 Kibana 实例并使用Grafana 变量 $__cell
引用了我从底层 Elasticsearch 查询中得到的 document_id:
https://mykibana.host/app/kibana#/doc/myindex-*/myindex-prod-*/logs?id=$__cell&_g=h@8b5b71a
不完美,但让我的仪表板保持可读性,并在需要时提供更多信息。更好的办法是在 ES 索引中添加一个短路字段,但目前我无法做到这一点。