如何在Grafana中查询Elasticsearch

时间:2019-04-10 05:58:08

标签: database elasticsearch lucene grafana

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

我知道我在Elasticsearch中的数据不适合图形,但是我没有其他示例数据,我只想学习如何处理此查询。我已经使用 mysql和grafana 完成了类似的操作。 (数据不适用于图表,但我设法使其如下图所示) Mysql and Grafana

我想对Elasticsearch进行上述操作。由于他们使用 Lucene 查询(与Mysql不同),因此我阅读了一些信息。但是我不知道该放在哪里。我想在图表上显示 metascore votes (请查看底部的 Json )。

Elasticsearch and Grafana

我用过邮递员。
enter image description here 这是JSON类型数据。 (我想使用“投票”或“元得分”显示在图表上)

{
    "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”之类的示例,并且您需要@或_并在此处放置索引,然后在其中键入,等等)

enter image description here

1 个答案:

答案 0 :(得分:0)

我知道了。

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

Data sources

enter image description here 您将索引名称放在此处。最重要的是,您需要一个可以说明时间的字段。我使用日期字段。我做了一个简单的示例数据,如下所示。 (查看日期字段。) sample

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

enter image description here

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

enter image description here

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