Elasticsearch debug

倒腾一个新东西,首先是要了解基本概念,以后就是要学习如何 debug 。要否则很容易出现抓瞎的状况。搞定这两点剩下的就是耐心和恒心的问题了。html

Log level

通常 log 会根据不一样的 log level 输出不一样的内容。若是是开发模式,通常把 log level 设置为 debug 是和方便的。shell

Elasticsearch 的配置文件在 confg/ 目录下。
一共有两个文件,一个是 elasticsearch.yml ,是对 Elasticsearch 自己进行配置, 好比 cluster name 之类的。
一个是 logging.yml ,用来配置 log 。json

咱们只要在 logging.ymles.logger.level: INFO 改成 es.logger.level: DEBUG 便可。app

Logging Requests to Elasticsearch

我遇到的问题是的第三方库,对 request 作了封装,返回缺乏我须要的信息。而 clojure 又不方便去改库的源码。因此果断考虑用 Elasticsearch 的 log。curl

方法以下:elasticsearch

elasticsearch.yml file

能够经过更改 elasticsearch.yml 达到 log request 的目的。加入如下代码:ide

index.search.slowlog.threshold.query.debug: 0s
index.search.slowlog.threshold.fetch.debug: 0s
index.indexing.slowlog.threshold.index.debug: 0s

默认的 log 输出在 logs/elasticsearch_index_indexing_slowlog.loglogs/elasticsearch_index_search_slowlog.log 里。能够经过 tail -f 进行查看。学习

顺带一提,Elasticsearch 自动按时间作了分割,大赞。fetch

配置完,咱们能够经过 http://localhost:9200/_settings 查看咱们的配置是否成功。ui

Runtime Settings

咱们还能够经过 HTTP API 更改设置,这样作的好处是能够不须要重启 Elasticsearch 。

curl -XPUT "http://localhost:9200/_settings"  -H 'Content-Type: application/json' -d'
{
    "index.search.slowlog.threshold.query.debug": "0s",
    "index.search.slowlog.threshold.fetch.debug": "0s",
    "index.indexing.slowlog.threshold.index.debug": "0s"
}'

小结

Elasticsearch 使用起来很舒服,不管是文档,仍是 API,都很是好用。有不少让人眼前一亮的小细节,好比在请求里加上 `pretty' ,会有漂亮的输出。

从这些小事能够看出,Elasticsearch 是一款很用心的产品。

参考

http://blog.florian-hopf.de/2...
https://www.elastic.co/guide/...

相关文章
相关标签/搜索