【问题标题】:How to log all executed elasticsearch queries如何记录所有已执行的弹性搜索查询
【发布时间】:2014-03-12 01:56:33
【问题描述】:

我想查看针对 elasticsearch 实例执行的所有查询。是否可以在调试模式下运行 elasticsearch,或者告诉它存储针对它执行的所有查询?

目的是查看使用elasticsearch的软件启动了哪些查询进行分析。

【问题讨论】:

    标签: debugging elasticsearch analysis


    【解决方案1】:

    在 ElasticSearch 5 之前的版本中,您可以通过更改 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
    

    调整设置并重新启动您的节点,然后查阅日志以查看针对您的节点执行的查询。请注意生产日志文件的大小是否会迅速增加。

    【讨论】:

    • 它只记录慢查询吗?我想查看所有查询,它们仍然不在日志中。
    • @paweloque 调整时间段,以便捕获所有查询,而不仅仅是那些慢查询。
    • 更准确地说,您应该能够将时间阈值设置为零,从而记录每个查询。
    • 我也是谷歌。慢日志将在段级别而不是集群级别记录查询......实际上,如果有任何选项可以在集群级别记录查询,那会很好。
    • 这似乎不适用于当前的弹性。我将这些中的每一个都设置为零,但在慢日志中仍然一无所获....
    【解决方案2】:

    在 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:保留现有设置

    如果您不想覆盖现有设置,而只是添加新设置,请在 _settings 后添加 '''preserve_existing=true''',如下所示:

    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"
    }
    

    【讨论】:

    • 一行这样方便下次我回来(一个月后): curl -XPUT 'localhost:9200/_all/_settings' -d '{"index.indexing.slowlog.threshold.index.调试”:“0s”,“index.search.slowlog.threshold.fetch.debug”:“0s”,“index.search.slowlog.threshold.query.debug”:“0s”}'
    • 注意:输出现在出现在包含名称“slowlog”的日志文件中。对我来说是elastic_5_5_index_search_slowlog.log
    【解决方案3】:

    从版本 5 开始,ElasticSearch 会为此功能收费。它被称为“审计日志”,现在是 X-Pack 的一部分。有一个免费的基本许可证可用,但此许可证只为您提供简单的监控功能。身份验证、查询日志记录和所有这些相当基本的东西现在都需要花钱。

    【讨论】:

      【解决方案4】:

      是的,可以告诉 Elasticsearch 记录对其执行的所有查询,并且您可以配置日志记录级别,例如 DEBUG。您可以使用 curl 在 ES 7.13.x 中更改它:

      curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
      {
        "transient": {
          "logger.org.elasticsearch.discovery": "DEBUG"
        }
      }
      '
      

      在 macOS 上,日志文件默认存储在 $ES_HOME。请查看有关Elasticsearch Logging的文档

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-12
        • 2016-07-20
        • 1970-01-01
        • 1970-01-01
        • 2014-10-18
        相关资源
        最近更新 更多