在Elasticsearch中,有两种主要类型的数据流:日志流(Logs)和指标流(Metrics)。这两种数据流类型在用途和处理方式上有一些差异。
Logs数据流类型用于传输结构化数据,并且通常包含产生于应用程序、操作系统或网络设备中的日志消息。 在发送数据流之前,用户需要预定义索引模板,以确保提取的结构化数据格式正确。在对数据流的分析和搜索过程中,用户可以使用Elasticsearch分布式相关性搜索(Query DSL)和Data Visualizer等工具。
示例代码:
PUT _index_template/log_template { "index_patterns": ["log-*"], "template": { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "@timestamp": { "type": "date" }, "level": { "type": "keyword" }, "message": { "type": "text" } } } } }
PUT _data_stream/logs { "template": { "name": "log_template" } }
Metrics数据流类型通常用于传输数字测量结果,例如应用程序指标、服务器资源使用情况和网络流量。 Metrics数据流提供了丰富的可视化操作,包括Gauge、Counters等聚合和监控数据可视化功能。 在创建Metrics数据流之前,用户需要定义具有所需度量标准的索引模板。
示例代码:
PUT _index_template/metrics_template { "index_patterns": ["metric-*"], "template": { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "@timestamp": {