1. Home
  2. Logs
  3. Database Servers
  4. A Guide to Elasticsearch Logs

A Guide to Elasticsearch Logs

Elasticsearch, a powerful distributed search and analytics engine, generates detailed logs that help administrators monitor performance, troubleshoot issues, and secure their systems. This guide explores the various types of Elasticsearch logs, their purposes, and best practices for effective log management.


Types of Elasticsearch Logs

Elasticsearch generates several types of logs that provide insights into different aspects of its operation.

1. Server Logs

  • Purpose: Tracks general server activity, including cluster events, node joins/leaves, and configuration changes.
  • Location: By default, located in the logs directory within the Elasticsearch installation path (e.g., /var/log/elasticsearch/).
  • Common Use Cases:
    • Diagnosing server startup issues.
    • Monitoring cluster lifecycle events.

Example:

[2024-11-20T12:00:00,123][INFO ][o.e.n.Node] [node-1] initializing ...
[2024-11-20T12:00:05,789][INFO ][o.e.c.c.ClusterService] [node-1] new_master {node-1}{ID123}{127.0.0.1}{127.0.0.1:9300}{http_enabled=true}, reason: master node changed

2. Cluster Logs

  • Purpose: Records events at the cluster level, such as shard relocations, index creation/deletion, and master elections.
  • Common Use Cases:
    • Debugging cluster state inconsistencies.
    • Monitoring shard allocation and replication.

Example:

[2024-11-20T12:15:00,456][INFO ][o.e.c.r.a.AllocationService] [node-2] Cluster health status changed from [YELLOW] to [GREEN]

3. Slow Logs

  • Purpose: Captures slow queries and indexing operations for performance analysis.
  • Enablement: Configure the index.search.slowlog and index.indexing.slowlog settings.
  • Common Use Cases:
    • Identifying inefficient queries.
    • Optimizing indexing operations.

Example (Search Slow Log):

[2024-11-20T12:30:00,789][WARN ][i.s.s.q.QueryPhase] [node-1] took[5s] to execute search for index [products] with query { "match": { "name": "Elasticsearch" } }

Example (Indexing Slow Log):

[2024-11-20T12:35:00,456][WARN ][i.s.s.i.IndexingSlowLog] [node-1] took[3s] to index document into [products][_doc]

4. Access Logs

  • Purpose: Tracks HTTP requests made to the Elasticsearch REST API, including queries and updates.
  • Enablement: Requires configuration of a reverse proxy (e.g., Nginx) or audit logging (if using X-Pack).
  • Common Use Cases:
    • Auditing API usage.
    • Identifying unauthorized access attempts.

Example:

127.0.0.1 - admin [20/Nov/2024:12:40:00 +0000] "GET /_search HTTP/1.1" 200 512

5. GC (Garbage Collection) Logs

  • Purpose: Monitors Java garbage collection events, which can affect Elasticsearch performance.
  • Enablement: Configure JVM options in the jvm.options file.
  • Common Use Cases:
    • Diagnosing high latency or out-of-memory errors.
    • Monitoring JVM heap usage.

Example:

[2024-11-20T12:45:00.123+0000][gc][young][1234] GC (Allocation Failure) 200M->150M(300M)

6. Audit Logs

  • Purpose: Captures security-related events, such as user authentications and role changes (available with X-Pack).
  • Enablement: Configure audit logging in the elasticsearch.yml file.
  • Common Use Cases:
    • Ensuring compliance with security policies.
    • Investigating suspicious activity.

Example:

[2024-11-20T12:50:00,789][INFO ][o.e.x.s.a.AuditTrailService] [node-1] User [admin] logged in with roles [superuser]

7. Deprecation Logs

  • Purpose: Warns about the use of deprecated features or APIs.
  • Enablement: Enabled by default.
  • Common Use Cases:
    • Preparing for Elasticsearch version upgrades.
    • Updating deprecated query syntax or configurations.

Example:

[2024-11-20T12:55:00,123][WARN ][o.e.d.a.DeprecationLogger] [node-1] The '_type' field is deprecated and will be removed in future releases

Managing Elasticsearch Logs

Effective log management ensures Elasticsearch logs are actionable and do not overwhelm system resources.

1. Configure Logging

  • Use the log4j2.properties file to customize logging levels and output.
    • Default levels include DEBUG, INFO, WARN, and ERROR.
    • Adjust verbosity to suit development or production environments.

2. Rotate Logs

  • Elasticsearch supports built-in log rotation through log4j2.properties.
  • Alternatively, use external tools like logrotate for advanced log rotation and compression.

Example Log Rotation Rule:

/var/log/elasticsearch/*.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
}

3. Centralized Monitoring

  • Integrate Elasticsearch logs into centralized log management solutions like:
    • ELK Stack: Elasticsearch, Logstash, and Kibana for full-stack monitoring.
    • Third-Party Tools: Splunk, Datadog, or Graylog for distributed environments.

4. Secure Logs

  • Restrict access to logs to authorized personnel only.
  • Use encryption and secure log storage to comply with security policies.

5. Backup Logs

  • Include logs in your backup strategy for historical analysis and compliance.

Elasticsearch logs are invaluable tools for monitoring, troubleshooting, and securing your clusters. By understanding the different log types and implementing best practices for managing them, you can maintain a high-performing and resilient Elasticsearch environment tailored to your operational needs.

Updated on November 20, 2024
Was this article helpful?

Related Articles