gpt4 book ai didi

database - 如何在 Grafana 中查询 Elasticsearch

转载 作者:行者123 更新时间:2023-12-02 22:55:38 26 4
gpt4 key购买 nike

我在 Elasticsearch 中有以下数据。(由于数据有点长,我已将其附在底部。)我正在尝试弄清楚如何查询以显示Grafana 中的图表上的某些内容。

我知道我在 elasticsearch 中的数据不适合图表,但我没有任何其他示例数据,我只想学习如何处理此查询。我用 mysql 和 grafana 做过类​​似的事情。 (数据不适合图表,但我设法使其如下图所示) Mysql and Grafana

我想用 Elasticsearch 完成上述工作。由于他们使用 Lucene 查询(不同于 Mysql),我阅读了一些相关信息。但我不知道该放在哪里。我想在图表上显示 metacorevotes(请查看底部的 Json)。

Elasticsearch and Grafana

我用过 postman 。
enter image description here这是 JSON 类型的数据。 (我想用“votes”或“metacore”出现在图表上)

{
"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
}
}
]
}
}

如果这些数据无法显示在图表上,那么您能否给我一些提示,说明我可以在下面的查询和指标字段中输入什么内容,以便在我有其他示例数据时可以处理这个问题。我需要一个像'metacore'这样的例子应该放在这个字段中,你需要@或_并将索引放在这里,然后在那里输入等)

enter image description here

最佳答案

我想通了。

首先,您需要进入Grafana中的Data Sources,并选择Elasticsearch

Data sources

enter image description here你把你的index名字放在这里。最重要的是,您需要一个可以分辨时间的字段。我使用了日期字段。我制作了一个简单的示例数据,如下所示。 (查看 日期 字段。) sample

转到 Grafana 仪表板。在查询中,您会看到 Date Histogram 将自动设置为 date。选择所需的指标。

enter image description here

您会在图表上看到类似的内容。

enter image description here

我知道我的数据、字段等不是理想的图表 Material 。但我关注的是如何,而不是什么。请将此视为 Elastic 和 Grafana 的“hello world”。希望这可以帮助某人并节省他们的时间和精力。

关于database - 如何在 Grafana 中查询 Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55605633/

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