<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>opensearch on </title>
    <link>/tags/opensearch/</link>
    <description>Recent content in opensearch on </description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Tue, 07 Apr 2026 10:00:00 +0800</lastBuildDate><atom:link href="/tags/opensearch/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Spring Boot 3.4&#43; 结构化日志实践记录：用 ECS &#43; Fluent API</title>
      <link>/posts/spring-boot-structured-logging-ecs/</link>
      <pubDate>Tue, 07 Apr 2026 10:00:00 +0800</pubDate>
      
      <guid>/posts/spring-boot-structured-logging-ecs/</guid>
      <description>为什么我开始关注结构化输出 Spring Boot 默认的 Logback 输出是人类可读的文本行，形如：
2026-04-07 10:00:00.123 INFO 12345 --- [main] c.e.OrderService : order created orderId=ORD-001 这在本地开发时没有问题，但一旦日志进入 OpenSearch，文本行只能靠全文检索（message: *ORD-001*）来定位，无法按字段过滤、聚合统计或设置告警规则。当并发量上来，同一秒内几百条日志里找一个 orderId 靠的是运气而不是索引。
解决这个问题的方式是让每条日志以结构化 JSON 格式输出，每个上下文值都成为独立字段，可以被 OpenSearch 精确索引和查询。Spring Boot 3.4 正式将这个能力内建进框架，开发者不再需要引入 logstash-logback-encoder 或手写复杂的 XML encoder 配置。
5 行配置启用 ECS 结构化输出 ECS（Elastic Common Schema）是 Elastic 定义的日志字段规范，OpenSearch 原生兼容。Spring Boot 3.4+ 内建了 ECS 格式支持，至少在这个场景里，只需要在 application.yml 里声明：
spring: application: name: order-service logging: structured: format: # console 不设置：本地开发保留 Logback 默认彩色文本（不设置即为默认行为） # console: ecs # 容器环境如需从 stdout 采集，将此行取消注释 file: ecs # 生产输出：ECS JSON file: name: logs/app.</description>
    </item>
    
  </channel>
</rss>
