簡體   English   中英

如何在Grafana中查詢Elasticsearch

[英]How to query to Elasticsearch in Grafana

我在Elasticsearch中有以下數據。(由於數據有點長,我已將它附加在底部。)我試圖弄清楚如何查詢以便在Grafana中的圖形上顯示某些內容

我知道我在elasticsearch中的數據不適合圖形,但我沒有任何其他樣本數據,我只是想學習如何處理這個查詢。 我用mysql和grafana做過類似的事情。 (數據不適合圖表,但我設法使其像下面的圖像一樣) Mysql和Grafana

我想用Elasticsearch做上面的事情。 由於他們使用Lucene查詢(與Mysql不同),我閱讀了一些相關的信息。 但我沒有找到放在哪里的線索。 我想在圖表上顯示metascore或者投票 (請查看底部的Json )。

Elasticsearch和Grafana

我用過郵差。
在此輸入圖像描述 這是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”。 希望這可以幫助某人並節省他們的時間和精力。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM