我想查看針對elasticsearch實例執行的所有查詢。是否可以在調試模式下運行elasticsearch,或者告訴它存儲所有針對它執行的查詢?查看所有執行的elasticsearch查詢
目的是查看從使用elasticsearch進行分析的軟件啓動哪些查詢。
我想查看針對elasticsearch實例執行的所有查詢。是否可以在調試模式下運行elasticsearch,或者告訴它存儲所有針對它執行的查詢?查看所有執行的elasticsearch查詢
目的是查看從使用elasticsearch進行分析的軟件啓動哪些查詢。
在5之前的ElasticSearch版本中,您可以通過更改ElasticSearch.yml配置文件來完成此操作。在該文件的最底部,可以調整記錄時間來記錄所有:
index.search.slowlog.threshold.query.warn: 10s
index.search.slowlog.threshold.query.info: 5s
index.search.slowlog.threshold.query.debug: 2s
index.search.slowlog.threshold.query.trace: 500ms
index.search.slowlog.threshold.fetch.warn: 1s
index.search.slowlog.threshold.fetch.info: 800ms
index.search.slowlog.threshold.fetch.debug: 500ms
index.search.slowlog.threshold.fetch.trace: 200ms
index.indexing.slowlog.threshold.index.warn: 10s
index.indexing.slowlog.threshold.index.info: 5s
index.indexing.slowlog.threshold.index.debug: 2s
index.indexing.slowlog.threshold.index.trace: 500ms
調整設置,並重新啓動您的節點,然後諮詢日誌,查看對您的節點執行的查詢。請注意,如果生產日誌文件的大小會迅速增加。
從版本5開始,ElasticSearch向此功能收取費用。它被稱爲「審計日誌」,現在是X-Pack的一部分。有一個免費的基本許可證,但該許可證僅爲您提供簡單的監控功能。身份驗證,查詢日誌和所有這些相當基本的東西現在花錢。
在版本5.x中,您必須設置每個索引的緩慢日誌記錄。
命令行:
curl -XPUT 'http://localhost:9200/myindexname/_settings' -d '{
"index.indexing.slowlog.threshold.index.debug" : "0s",
"index.search.slowlog.threshold.fetch.debug" : "0s",
"index.search.slowlog.threshold.query.debug" : "0s"
}'
或者,如果你正在使用Kibana,轉到開發工具欄,然後輸入:
PUT /myindexname/_settings
{"index.indexing.slowlog.threshold.index.debug": "0s",
"index.search.slowlog.threshold.fetch.debug" : "0s",
"index.search.slowlog.threshold.query.debug": "0s"}
#1:適用於全部指數
您可以將設置所有指數使用下面的命令:
PUT /_all/_settings
{"index.indexing.slowlog.threshold.index.debug": "0s",
"index.search.slowlog.threshold.fetch.debug" : "0s",
"index.search.slowlog.threshold.query.debug": "0s"}
#2:保留現有設置
如果您不想覆蓋現有設置,而只是添加新的,添加「」「preserve_existing =真正的」 _settings後',像這樣:
PUT /_all/_settings?preserve_existing=true
{"index.indexing.slowlog.threshold.index.debug": "0s",
"index.search.slowlog.threshold.fetch.debug" : "0s",
"index.search.slowlog.threshold.query.debug": "0s"}
上述要求,只會增加設置,如果它們不存在。如果它們已經在那裏,它不會改變它們。
#3:所有可用的日誌設置
所有可用的慢日誌設置爲here及以下,供大家參考:
PUT /test_index/_settings
{
"index.search.slowlog.threshold.query.warn": "60s",
"index.search.slowlog.threshold.query.info": "5s",
"index.search.slowlog.threshold.query.debug": "1s",
"index.search.slowlog.threshold.query.trace": "0.1s",
"index.search.slowlog.threshold.fetch.warn": "30s",
"index.search.slowlog.threshold.fetch.info": "5s",
"index.search.slowlog.threshold.fetch.debug": "1s",
"index.search.slowlog.threshold.fetch.trace": "0.1s",
"index.indexing.slowlog.threshold.index.warn": "6s",
"index.indexing.slowlog.threshold.index.info": "5s",
"index.indexing.slowlog.threshold.index.debug": "1s",
"index.indexing.slowlog.threshold.index.trace": "0.1s",
"index.indexing.slowlog.level": "info",
"index.indexing.slowlog.source": "1000"
}
是否僅記錄慢查詢?我想查看所有查詢,但它們仍然不在日誌中。 – paweloque
@paweloque調整時間段,以便捕獲所有查詢,而不僅僅是那些緩慢的查詢。 – Nate
要更準確地說明它,您應該能夠將時間閾值設置爲零,從而獲取每個查詢記錄。 –