如何在Grafana中查询Elasticsearch
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Grafana中查询Elasticsearch相关的知识,希望对你有一定的参考价值。
我在Elasticsearch中有以下数据。(由于数据有点长,我已将它附加在底部。)我试图弄清楚如何查询以便在Grafana中的图形上显示某些内容。
我知道我在elasticsearch中的数据不适合图形,但我没有任何其他样本数据,我只是想学习如何处理这个查询。我用mysql和grafana做过类似的事情。 (数据不适合图表,但我设法使其像下面的图像)
我想用Elasticsearch做上面的事情。由于他们使用Lucene查询(与Mysql不同),我阅读了一些相关的信息。但我没有找到放在哪里的线索。我想在图表上显示metascore或者投票(请查看底部的Json)。
我用过邮差。 这是JSON类型的数据。 (我想用'投票'或'metascore'出现在图表上)
{
"took": 113,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 8,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "movies",
"_type": "movie",
"_id": "dzb6AGoBnuCYnlTWZNmc",
"_score": 1,
"_source": {
"name": "Justice League",
"genre": "Action",
"summary": "Fueled by his restored faith in humanity and inspired by Superman's selfless act, Bruce Wayne enlists the help of his newfound ally, Diana Prince, to face an even greater enemy",
"yearofrelease": 201,
"metascore": 45,
"votes": 275122,
"rating": 6.6
}
},
{
"_index": "movies",
"_type": "movie",
"_id": "1",
"_score": 1,
"_source": {
"name": "Justice League1",
"genre": "Action1",
"summary": "Fueled by his restored faith in humanity and inspired by Superman's selfless act, Bruce Wayne enlists the help of his newfound ally, Diana Prince, to face an even greater enemy",
"yearofrelease": 201,
"metascore": 45,
"votes": 275122,
"rating": 6.6
}
},
{
"_index": "movies",
"_type": "movie",
"_id": "2",
"_score": 1,
"_source": {
"name": "Justice League",
"genre": "Action",
"summary": "Fueled by his restored faith in humanity and inspired by Superman's selfless act, Bruce Wayne enlists the help of his newfound ally, Diana Prince, to face an even greater enemy",
"yearofrelease": 2011,
"metascore": 45,
"votes": 275122,
"rating": 6.6
}
},
{
"_index": "movies",
"_type": "movie",
"_id": "hDYYAWoBnuCYnlTWyNmZ",
"_score": 1,
"_source": {
"name": "Thor Ragnarok",
"genre": "Action",
"summary": "Thor is imprisoned on the planet Sakaar, and must race against time to return to Asgard and stop Ragnarök, the destruction of his world, at the hands of the powerful and ruthless villain Hela",
"yearofrelease": 2017,
"metascore": 74,
"votes": 374270,
"rating": 7.9
}
},
{
"_index": "movies",
"_type": "movie",
"_id": "hTYYAWoBnuCYnlTWyNmZ",
"_score": 1,
"_source": {
"name": "Infinity War",
"genre": "Sci-Fi",
"summary": "The Avengers and their allies must be willing to sacrifice all in an attempt to defeat the powerful Thanos before his blitz of devastation and ruin puts an end to the universe",
"yearofrelease": 2018,
"metascore": 68,
"votes": 450856,
"rating": 8.6
}
},
{
"_index": "movies",
"_type": "movie",
"_id": "hzYYAWoBnuCYnlTW-9mV",
"_score": 1,
"_source": {
"name": "Thor Ragnarok",
"genre": "Action",
"summary": "Thor is imprisoned on the planet Sakaar, and must race against time to return to Asgard and stop Ragnarök, the destruction of his world, at the hands of the powerful and ruthless villain Hela",
"yearofrelease": 2017,
"metascore": 74,
"votes": 374270,
"rating": 7.9
}
},
{
"_index": "movies",
"_type": "movie",
"_id": "iDYYAWoBnuCYnlTW-9mV",
"_score": 1,
"_source": {
"name": "Infinity War",
"genre": "Sci-Fi",
"summary": "The Avengers and their allies must be willing to sacrifice all in an attempt to defeat the powerful Thanos before his blitz of devastation and ruin puts an end to the universe",
"yearofrelease": 2018,
"metascore": 68,
"votes": 450856,
"rating": 8.6
}
},
{
"_index": "movies",
"_type": "movie",
"_id": "iTYYAWoBnuCYnlTW-9mV",
"_score": 1,
"_source": {
"name": "Christopher Robin",
"genre": "Comedy",
"summary": "A working-class family man, Christopher Robin, encounters his childhood friend Winnie-the-Pooh, who helps him to rediscover the joys of life",
"yearofrelease": 2018,
"metascore": 60,
"votes": 9648,
"rating": 7.9
}
}
]
}
}
如果这些数据无法在图表上显示,那么您能否给我一些关于我可以在下面的查询和度量字段中添加的内容的提示,以便在我有其他样本数据时可以使用它。我需要一个像'metascore'这样的例子应该进入这个领域,你需要@或_并在这里输入索引,然后输入等等)
我想到了。
首先,您需要转到Grafana中的Data Sources,然后选择Elasticsearch。
你把你的索引名称放在这里。最重要的是,你需要一个可以分辨时间的领域。我用了日期字段。我制作了一个简单的样本数据,如下所示。 (查看日期字段。)
转到Grafana仪表板。在查询中,您将看到日期直方图将自动设置为日期。选择所需的指标。
您将在图表上看到类似的内容。
我知道我的数据,字段等不是理想的图形素材。但我专注于如何,而不是什么。请将此视为Elastic和Grafana的“hello world”。希望这可以帮助某人并节省他们的时间和精力。
以上是关于如何在Grafana中查询Elasticsearch的主要内容,如果未能解决你的问题,请参考以下文章
Grafana + Prometheus 如何在查询指标中使用正则表达式?
如何在 Grafana 的 MySQL 查询中使用 like?
如何在 aliasByNode() 函数中获取 Grafana 石墨查询中“*”节点的节点名称