如何在Grafana中查询Elasticsearch

Jin*_*Lee 3 database lucene elasticsearch grafana

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

\n\n

我知道我在elasticsearch中的数据不适合图形,但我没有任何其他示例数据,我只是想学习如何处理这个查询。我已经用mysql 和 grafana做了类似的事情。(数据不适合图表,但我设法使其如下图所示)\nMysql 和 Grafana

\n\n

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

\n\n

Elasticsearch 和 Grafana

\n\n

我用的是邮递员。
\n在此输入图像描述\n这里是JSON类型数据。(我想使用“投票”或“元分数”出现在图表上)

\n\n
{\n    "took": 113,\n    "timed_out": false,\n    "_shards": {\n        "total": 1,\n        "successful": 1,\n        "skipped": 0,\n        "failed": 0\n    },\n    "hits": {\n        "total": {\n            "value": 8,\n            "relation": "eq"\n        },\n        "max_score": 1,\n        "hits": [\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "dzb6AGoBnuCYnlTWZNmc",\n                "_score": 1,\n                "_source": {\n                    "name": "Justice League",\n                    "genre": "Action",\n                    "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",\n                    "yearofrelease": 201,\n                    "metascore": 45,\n                    "votes": 275122,\n                    "rating": 6.6\n                }\n            },\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "1",\n                "_score": 1,\n                "_source": {\n                    "name": "Justice League1",\n                    "genre": "Action1",\n                    "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",\n                    "yearofrelease": 201,\n                    "metascore": 45,\n                    "votes": 275122,\n                    "rating": 6.6\n                }\n            },\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "2",\n                "_score": 1,\n                "_source": {\n                    "name": "Justice League",\n                    "genre": "Action",\n                    "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",\n                    "yearofrelease": 2011,\n                    "metascore": 45,\n                    "votes": 275122,\n                    "rating": 6.6\n                }\n            },\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "hDYYAWoBnuCYnlTWyNmZ",\n                "_score": 1,\n                "_source": {\n                    "name": "Thor Ragnarok",\n                    "genre": "Action",\n                    "summary": "Thor is imprisoned on the planet Sakaar, and must race  against time to return to Asgard and stop Ragnar\xc3\xb6k, the destruction of his world, at the hands of the powerful and ruthless villain Hela",\n                    "yearofrelease": 2017,\n                    "metascore": 74,\n                    "votes": 374270,\n                    "rating": 7.9\n                }\n            },\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "hTYYAWoBnuCYnlTWyNmZ",\n                "_score": 1,\n                "_source": {\n                    "name": "Infinity War",\n                    "genre": "Sci-Fi",\n                    "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",\n                    "yearofrelease": 2018,\n                    "metascore": 68,\n                    "votes": 450856,\n                    "rating": 8.6\n                }\n            },\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "hzYYAWoBnuCYnlTW-9mV",\n                "_score": 1,\n                "_source": {\n                    "name": "Thor Ragnarok",\n                    "genre": "Action",\n                    "summary": "Thor is imprisoned on the planet Sakaar, and must race  against time to return to Asgard and stop Ragnar\xc3\xb6k, the destruction of his world, at the hands of the powerful and ruthless villain Hela",\n                    "yearofrelease": 2017,\n                    "metascore": 74,\n                    "votes": 374270,\n                    "rating": 7.9\n                }\n            },\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "iDYYAWoBnuCYnlTW-9mV",\n                "_score": 1,\n                "_source": {\n                    "name": "Infinity War",\n                    "genre": "Sci-Fi",\n                    "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",\n                    "yearofrelease": 2018,\n                    "metascore": 68,\n                    "votes": 450856,\n                    "rating": 8.6\n                }\n            },\n            {\n                "_index": "movies",\n                "_type": "movie",\n                "_id": "iTYYAWoBnuCYnlTW-9mV",\n                "_score": 1,\n                "_source": {\n                    "name": "Christopher Robin",\n                    "genre": "Comedy",\n                    "summary": "A working-class family man, Christopher Robin, encounters his childhood friend Winnie-the-Pooh, who helps him to  rediscover the joys of life",\n                    "yearofrelease": 2018,\n                    "metascore": 60,\n                    "votes": 9648,\n                    "rating": 7.9\n                }\n            }\n        ]\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果这些数据无法显示在图表上,那么您能否给我一些关于可以在下面的查询和指标字段中放入哪些内容的提示,以便我在有其他示例数据时可以进行此操作。我需要一个像“metascore”这样的例子应该放在这个字段中,你需要@或_并在此处放置索引,然后在此处键入,等等)

\n\n

在此输入图像描述

\n

Jin*_*Lee 9

我想到了。

首先,您需要转到Grafana中的数据源,然后选择 Elasticsearch

数据源

在此输入图像描述 您将索引名称放在这里。最重要的是,您需要一个可以显示时间的字段。我使用了日期字段。我制作了一个简单的示例数据,如下所示。(查看日期字段。) 样本

转到 Grafana 仪表板。在查询中,您将看到日期直方图将自动设置为date。选择您想要的指标。

在此输入图像描述

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

在此输入图像描述

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