slowlog.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. [[index-modules-slowlog]]
  2. == Slow Log
  3. [float]
  4. [[search-slow-log]]
  5. === Search Slow Log
  6. Shard level slow search log allows to log slow search (query and fetch
  7. phases) into a dedicated log file.
  8. Thresholds can be set for both the query phase of the execution, and
  9. fetch phase, here is a sample:
  10. [source,yaml]
  11. --------------------------------------------------
  12. index.search.slowlog.threshold.query.warn: 10s
  13. index.search.slowlog.threshold.query.info: 5s
  14. index.search.slowlog.threshold.query.debug: 2s
  15. index.search.slowlog.threshold.query.trace: 500ms
  16. index.search.slowlog.threshold.fetch.warn: 1s
  17. index.search.slowlog.threshold.fetch.info: 800ms
  18. index.search.slowlog.threshold.fetch.debug: 500ms
  19. index.search.slowlog.threshold.fetch.trace: 200ms
  20. --------------------------------------------------
  21. All of the above settings are _dynamic_ and can be set for each index using the
  22. <<indices-update-settings, update indices settings>> API. For example:
  23. [source,console]
  24. --------------------------------------------------
  25. PUT /twitter/_settings
  26. {
  27. "index.search.slowlog.threshold.query.warn": "10s",
  28. "index.search.slowlog.threshold.query.info": "5s",
  29. "index.search.slowlog.threshold.query.debug": "2s",
  30. "index.search.slowlog.threshold.query.trace": "500ms",
  31. "index.search.slowlog.threshold.fetch.warn": "1s",
  32. "index.search.slowlog.threshold.fetch.info": "800ms",
  33. "index.search.slowlog.threshold.fetch.debug": "500ms",
  34. "index.search.slowlog.threshold.fetch.trace": "200ms"
  35. }
  36. --------------------------------------------------
  37. // TEST[setup:twitter]
  38. By default thresholds are disabled (set to `-1`).
  39. The logging is done on the shard level scope, meaning the execution of a
  40. search request within a specific shard. It does not encompass the whole
  41. search request, which can be broadcast to several shards in order to
  42. execute. Some of the benefits of shard level logging is the association
  43. of the actual execution on the specific machine, compared with request
  44. level.
  45. The search slow log file is configured in the `log4j2.properties` file.
  46. [float]
  47. ==== Identifying search slow log origin
  48. It is often useful to identify what triggered a slow running query. If a call was initiated with an `X-Opaque-ID` header, then the user ID
  49. is included in Search Slow logs as an additional **id** field
  50. [source,js]
  51. ---------------------------
  52. {
  53. "type": "index_search_slowlog",
  54. "timestamp": "2030-08-30T11:59:37,786+02:00",
  55. "level": "WARN",
  56. "component": "i.s.s.query",
  57. "cluster.name": "distribution_run",
  58. "node.name": "node-0",
  59. "message": "[index6][0]",
  60. "took": "78.4micros",
  61. "took_millis": "0",
  62. "total_hits": "0 hits",
  63. "stats": "[]",
  64. "search_type": "QUERY_THEN_FETCH",
  65. "total_shards": "1",
  66. "source": "{\"query\":{\"match_all\":{\"boost\":1.0}}}",
  67. "id": "MY_USER_ID",
  68. "cluster.uuid": "Aq-c-PAeQiK3tfBYtig9Bw",
  69. "node.id": "D7fUYfnfTLa2D7y-xw6tZg"
  70. }
  71. ---------------------------
  72. // NOTCONSOLE
  73. [float]
  74. [[index-slow-log]]
  75. === Index Slow log
  76. The indexing slow log, similar in functionality to the search slow
  77. log. The log file name ends with `_index_indexing_slowlog.json`. Log and
  78. the thresholds are configured in the same way as the search slowlog.
  79. Index slowlog sample:
  80. [source,yaml]
  81. --------------------------------------------------
  82. index.indexing.slowlog.threshold.index.warn: 10s
  83. index.indexing.slowlog.threshold.index.info: 5s
  84. index.indexing.slowlog.threshold.index.debug: 2s
  85. index.indexing.slowlog.threshold.index.trace: 500ms
  86. index.indexing.slowlog.source: 1000
  87. --------------------------------------------------
  88. All of the above settings are _dynamic_ and can be set for each index using the
  89. <<indices-update-settings, update indices settings>> API. For example:
  90. [source,console]
  91. --------------------------------------------------
  92. PUT /twitter/_settings
  93. {
  94. "index.indexing.slowlog.threshold.index.warn": "10s",
  95. "index.indexing.slowlog.threshold.index.info": "5s",
  96. "index.indexing.slowlog.threshold.index.debug": "2s",
  97. "index.indexing.slowlog.threshold.index.trace": "500ms",
  98. "index.indexing.slowlog.source": "1000"
  99. }
  100. --------------------------------------------------
  101. // TEST[setup:twitter]
  102. By default Elasticsearch will log the first 1000 characters of the _source in
  103. the slowlog. You can change that with `index.indexing.slowlog.source`. Setting
  104. it to `false` or `0` will skip logging the source entirely an setting it to
  105. `true` will log the entire source regardless of size. The original `_source` is
  106. reformatted by default to make sure that it fits on a single log line. If preserving
  107. the original document format is important, you can turn off reformatting by setting
  108. `index.indexing.slowlog.reformat` to `false`, which will cause the source to be
  109. logged "as is" and can potentially span multiple log lines.
  110. The index slow log file is configured in the `log4j2.properties` file.