| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 | [[index-modules-slowlog]]== Slow Log[float][[search-slow-log]]=== Search Slow LogShard level slow search log allows to log slow search (query and fetchphases) into a dedicated log file.Thresholds can be set for both the query phase of the execution, andfetch phase, here is a sample:[source,yaml]--------------------------------------------------index.search.slowlog.threshold.query.warn: 10sindex.search.slowlog.threshold.query.info: 5sindex.search.slowlog.threshold.query.debug: 2sindex.search.slowlog.threshold.query.trace: 500msindex.search.slowlog.threshold.fetch.warn: 1sindex.search.slowlog.threshold.fetch.info: 800msindex.search.slowlog.threshold.fetch.debug: 500msindex.search.slowlog.threshold.fetch.trace: 200msindex.search.slowlog.level: info--------------------------------------------------All of the above settings are _dynamic_ and can be set for each index using the<<indices-update-settings, update indices settings>> API. For example: [source,console]--------------------------------------------------PUT /twitter/_settings{    "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.search.slowlog.level": "info"}--------------------------------------------------// TEST[setup:twitter]By default, none are enabled (set to `-1`). Levels (`warn`, `info`,`debug`, `trace`) allow to control under which logging level the logwill be logged. Not all are required to be configured (for example, only`warn` threshold can be set). The benefit of several levels is theability to quickly "grep" for specific thresholds breached.The logging is done on the shard level scope, meaning the execution of asearch request within a specific shard. It does not encompass the wholesearch request, which can be broadcast to several shards in order toexecute. Some of the benefits of shard level logging is the associationof the actual execution on the specific machine, compared with requestlevel.The logging file is configured by default using the followingconfiguration (found in `log4j2.properties`):[source,properties]--------------------------------------------------appender.index_search_slowlog_rolling.type = RollingFileappender.index_search_slowlog_rolling.name = index_search_slowlog_rollingappender.index_search_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog.logappender.index_search_slowlog_rolling.layout.type = PatternLayoutappender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] [%node_name]%marker %.-10000m%nappender.index_search_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog-%i.log.gzappender.index_search_slowlog_rolling.policies.type = Policiesappender.index_search_slowlog_rolling.policies.size.type = SizeBasedTriggeringPolicyappender.index_search_slowlog_rolling.policies.size.size = 1GBappender.index_search_slowlog_rolling.strategy.type = DefaultRolloverStrategyappender.index_search_slowlog_rolling.strategy.max = 4logger.index_search_slowlog_rolling.name = index.search.slowloglogger.index_search_slowlog_rolling.level = tracelogger.index_search_slowlog_rolling.appenderRef.index_search_slowlog_rolling.ref = index_search_slowlog_rollinglogger.index_search_slowlog_rolling.additivity = false--------------------------------------------------[float]==== Identifying search slow log originIt 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 IDis included in Search Slow logs as an additional **id** field (scroll to the right).[source,txt]---------------------------[2030-08-30T11:59:37,786][WARN ][i.s.s.query              ] [node-0] [index6][0] took[78.4micros], took_millis[0], total_hits[0 hits], stats[], search_type[QUERY_THEN_FETCH], total_shards[1], source[{"query":{"match_all":{"boost":1.0}}}], id[MY_USER_ID],---------------------------// NOTCONSOLEThe user ID is also included in JSON logs.[source,js]---------------------------{  "type": "index_search_slowlog",  "timestamp": "2030-08-30T11:59:37,786+02:00",  "level": "WARN",  "component": "i.s.s.query",  "cluster.name": "distribution_run",  "node.name": "node-0",  "message": "[index6][0]",  "took": "78.4micros",  "took_millis": "0",  "total_hits": "0 hits",  "stats": "[]",  "search_type": "QUERY_THEN_FETCH",  "total_shards": "1",  "source": "{\"query\":{\"match_all\":{\"boost\":1.0}}}",  "id": "MY_USER_ID",  "cluster.uuid": "Aq-c-PAeQiK3tfBYtig9Bw",  "node.id": "D7fUYfnfTLa2D7y-xw6tZg"}---------------------------// NOTCONSOLE[float][[index-slow-log]]=== Index Slow logThe indexing slow log, similar in functionality to the search slowlog. The log file name ends with `_index_indexing_slowlog.log`. Log andthe thresholds are configured in the same way as the search slowlog.Index slowlog sample:[source,yaml]--------------------------------------------------index.indexing.slowlog.threshold.index.warn: 10sindex.indexing.slowlog.threshold.index.info: 5sindex.indexing.slowlog.threshold.index.debug: 2sindex.indexing.slowlog.threshold.index.trace: 500msindex.indexing.slowlog.level: infoindex.indexing.slowlog.source: 1000--------------------------------------------------All of the above settings are _dynamic_ and can be set for each index using the<<indices-update-settings, update indices settings>> API. For example: [source,console]--------------------------------------------------PUT /twitter/_settings{    "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",    "index.indexing.slowlog.level": "info",    "index.indexing.slowlog.source": "1000"}--------------------------------------------------// TEST[setup:twitter]By default Elasticsearch will log the first 1000 characters of the _source inthe slowlog. You can change that with `index.indexing.slowlog.source`. Settingit to `false` or `0` will skip logging the source entirely an setting it to`true` will log the entire source regardless of size. The original `_source` isreformatted by default to make sure that it fits on a single log line. If preservingthe original document format is important, you can turn off reformatting by setting`index.indexing.slowlog.reformat` to `false`, which will cause the source to belogged "as is" and can potentially span multiple log lines.The index slow log file is configured by default in the `log4j2.properties`file:[source,properties]--------------------------------------------------appender.index_indexing_slowlog_rolling.type = RollingFileappender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rollingappender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog.logappender.index_indexing_slowlog_rolling.layout.type = PatternLayoutappender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] [%node_name]%marker %.-10000m%nappender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog-%i.log.gzappender.index_indexing_slowlog_rolling.policies.type = Policiesappender.index_indexing_slowlog_rolling.policies.size.type = SizeBasedTriggeringPolicyappender.index_indexing_slowlog_rolling.policies.size.size = 1GBappender.index_indexing_slowlog_rolling.strategy.type = DefaultRolloverStrategyappender.index_indexing_slowlog_rolling.strategy.max = 4logger.index_indexing_slowlog.name = index.indexing.slowlog.indexlogger.index_indexing_slowlog.level = tracelogger.index_indexing_slowlog.appenderRef.index_indexing_slowlog_rolling.ref = index_indexing_slowlog_rollinglogger.index_indexing_slowlog.additivity = false--------------------------------------------------
 |