Copilot commented on code in PR #13271: URL: https://github.com/apache/apisix/pull/13271#discussion_r3122037392
########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -40,21 +40,22 @@ The `elasticsearch-logger` Plugin pushes request and response logs in batches to | Name | Type | Required | Default | Description | | ------------- | ------- | -------- | --------------------------- | ------------------------------------------------------------ | | endpoint_addrs | array[string] | True | | Elasticsearch API endpoint addresses. If multiple endpoints are configured, they will be written randomly. | -| field | object | True | | Elasticsearch `field` configuration. | -| field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). | +| field | object | True | | Elasticsearch field configuration. | +| field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). Supports the configuration of a [lua time format](https://www.lua.org/pil/22.1.html) in curly brackets to include the current date, such as `service-{%Y-%m-%d}`. | +| field.type | string | False | | Elasticsearch [_type field](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-type-field.html#mapping-type-field). | | log_format | object | False | | Custom log format as key-value pairs in JSON. Values support strings and nested objects (up to five levels deep; deeper fields are truncated). Within strings, [APISIX](../apisix-variable.md) or [NGINX variables](http://nginx.org/en/docs/varindex.html) can be referenced by prefixing with `$`. | -| auth | array | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) configuration. | -| auth.username | string | True | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) username. | -| auth.password | string | True | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) password. | -| headers | object | False | | Custom headers to send with requests as key-value pairs. For example: `{"Authorization": "Bearer token", "X-API-Key": "key"}`. | +| auth | object | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) configuration. | +| auth.username | string | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) username. | +| auth.password | string | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) password. The secret is encrypted with AES before being stored in etcd. | Review Comment: `auth.username` and `auth.password` are marked as not required, but the plugin schema requires both fields when `auth` is provided (they’re required as a pair). Consider reflecting this in the table (e.g., “Required if `auth` is set”) to prevent partial `auth` configs that will fail schema validation. ```suggestion | auth.username | string | Required if `auth` is set | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) username. | | auth.password | string | Required if `auth` is set | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) password. The secret is encrypted with AES before being stored in etcd. | ``` ########## docs/zh/latest/plugins/elasticsearch-logger.md: ########## @@ -40,20 +40,23 @@ description: elasticsearch-logger Plugin 将请求和响应日志批量推送到 | 名称 | 类型 | 必选项 | 默认值 | 描述 | | ------------- | ------- | -------- | -------------------- | ------------------------------------------------------------ | -| endup_addrs | array[string] | 是 | | Elasticsearch API 端点地址。如果配置了多个端点,则会随机写入。 | -| field | object | 是 | | Elasticsearch `field` 配置。 | -| field.index | string | 是 | | Elasticsearch [_index 字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field)。 | +| endpoint_addrs | array[string] | 是 | | Elasticsearch API 端点地址。如果配置了多个端点,则会随机写入。 | +| field | object | 是 | | Elasticsearch 字段配置。 | +| field.index | string | 是 | | Elasticsearch [_index 字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field)。支持在花括号中使用 [lua 时间格式](https://www.lua.org/pil/22.1.html) 来包含当前日期,例如 `service-{%Y-%m-%d}`。 | +| field.type | string | 否 | | Elasticsearch [_type 字段](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-type-field.html#mapping-type-field)。 | | log_format | object | 否 | | 自定义日志格式以 JSON 的键值对声明。值支持字符串和嵌套对象(最多五层,超出部分将被截断)。字符串中可通过 `$` 前缀引用 [APISIX](../apisix-variable.md) 或 [NGINX 变量](http://nginx.org/en/docs/varindex.html)。 | -| auth | array | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 配置。 | -| auth.username | string | 是 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 用户名。 | -| auth.password | string | 是 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 密码。 | -| headers | object | 否 | | 自定义请求标头,以键值对形式配置。例如 `{"Authorization": "Bearer token", "X-API-Key": "key"}`。 | +| auth | object | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 配置。 | +| auth.username | string | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 用户名。 | +| auth.password | string | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 密码。该密钥在存储到 etcd 之前会使用 AES 加密。 | +| headers | object | 否 | | 自定义 HTTP 请求标头,以键值对形式包含在发送给 Elasticsearch 的请求中。可作为 `auth` 的替代或补充,用于身份验证和其他目的。在 APISIX 3.16.0 中可用。 | | ssl_verify | boolean | 否 | true | 如果为 true,则执行 SSL 验证。 | | timeout | integer | 否 | 10 | Elasticsearch 发送数据超时(秒)。 | | include_req_body | boolean | 否 | false |如果为 true,则将请求主体包含在日志中。请注意,如果请求主体太大而无法保存在内存中,则由于 NGINX 的限制而无法记录。| | include_req_body_expr | array[array] | 否 | | 一个或多个条件的数组,形式为 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。在 `include_req_body` 为 true 时使用。仅当此处配置的表达式计算结果为 true 时,才会记录请求主体。| +| max_req_body_bytes | integer | 否 | 524288 | >=1 | 记录请求主体的最大字节数。如果请求主体超过此值,则会在记录前截断。在 APISIX 3.16.0 中可用。 | | include_resp_body | boolean | 否 | false | 如果为 true,则将响应主体包含在日志中。| | include_resp_body_expr | array[array] | 否 | | 一个或多个条件的数组,形式为 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。在 `include_resp_body` 为 true 时使用。仅当此处配置的表达式计算结果为 true 时,才会记录响应主体。| +| max_resp_body_bytes | integer | 否 | 524288 | >=1 | 记录响应主体的最大字节数。如果响应主体超过此值,则会在记录前截断。在 APISIX 3.16.0 中可用。 | Review Comment: `max_req_body_bytes`/`max_resp_body_bytes` 这两行多加了一个 `>=1` 列,但当前属性表只有 5 列(没有“有效值”列),会导致 Markdown 表格渲染错位。建议要么在表头/分隔行中新增“有效值”列,要么把 `>=1` 合并到“描述”列里。 ```suggestion | max_req_body_bytes | integer | 否 | 524288 | 有效值:`>=1`。记录请求主体的最大字节数。如果请求主体超过此值,则会在记录前截断。在 APISIX 3.16.0 中可用。 | | include_resp_body | boolean | 否 | false | 如果为 true,则将响应主体包含在日志中。| | include_resp_body_expr | array[array] | 否 | | 一个或多个条件的数组,形式为 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。在 `include_resp_body` 为 true 时使用。仅当此处配置的表达式计算结果为 true 时,才会记录响应主体。| | max_resp_body_bytes | integer | 否 | 524288 | 有效值:`>=1`。记录响应主体的最大字节数。如果响应主体超过此值,则会在记录前截断。在 APISIX 3.16.0 中可用。 | ``` ########## docs/zh/latest/plugins/elasticsearch-logger.md: ########## @@ -40,20 +40,23 @@ description: elasticsearch-logger Plugin 将请求和响应日志批量推送到 | 名称 | 类型 | 必选项 | 默认值 | 描述 | | ------------- | ------- | -------- | -------------------- | ------------------------------------------------------------ | -| endup_addrs | array[string] | 是 | | Elasticsearch API 端点地址。如果配置了多个端点,则会随机写入。 | -| field | object | 是 | | Elasticsearch `field` 配置。 | -| field.index | string | 是 | | Elasticsearch [_index 字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field)。 | +| endpoint_addrs | array[string] | 是 | | Elasticsearch API 端点地址。如果配置了多个端点,则会随机写入。 | +| field | object | 是 | | Elasticsearch 字段配置。 | +| field.index | string | 是 | | Elasticsearch [_index 字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field)。支持在花括号中使用 [lua 时间格式](https://www.lua.org/pil/22.1.html) 来包含当前日期,例如 `service-{%Y-%m-%d}`。 | +| field.type | string | 否 | | Elasticsearch [_type 字段](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-type-field.html#mapping-type-field)。 | Review Comment: 这里声明 `field.index` 支持 `{...}` 中的 Lua 时间格式,以及新增了 `field.type` 属性,但插件实现只会原样使用 `conf.field.index`,也不会读取 `field.type`(仅在 ES 5/6 内部固定设置 `_type = "_doc"`)。请删除/修正这些描述,或在插件中实现对应能力以与文档一致。 ```suggestion | field.index | string | 是 | | Elasticsearch [_index 字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field)。 | ``` ########## docs/zh/latest/plugins/elasticsearch-logger.md: ########## @@ -446,3 +453,66 @@ curl -i "http://127.0.0.1:9080/anything" -X POST -d '{"env": "dev"}' ``` ::: + +### 在 Elasticsearch 索引中包含请求日期 + +以下示例演示了如何配置 `elasticsearch-logger` 插件,以在 Elasticsearch 索引名称中包含请求日期。 + +使用 `elasticsearch-logger` 创建路由,如下所示: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "elasticsearch-logger-route", + "uri": "/anything", + "plugins": { + "elasticsearch-logger": { + "endpoint_addrs": ["http://elasticsearch:9200"], + "field": { + "index": "apisix-{%Y.%m.%d}", + "type": "logs" + } + } + }, + "upstream": { + "nodes": { + "httpbin.org:80": 1 + }, + "type": "roundrobin" + } + }' +``` + +`index` 字段在花括号中使用 [lua 时间格式](https://www.lua.org/pil/22.1.html),将当前年、月、日附加到索引名称中。 + +向路由发送请求以生成日志条目: + +```shell +curl -i "http://127.0.0.1:9080/anything" +``` + +您应该会收到 `HTTP/1.1 200 OK` 响应。 + +导航到 [localhost:5601](http://localhost:5601) 上的 Kibana 仪表板,并在 __Discover__ 选项卡下创建一个新的索引模式 `apisix*` 以从 Elasticsearch 获取数据。配置完成后,导航回 __Discover__ 选项卡,您应该会看到生成的日志,索引名称中包含当前日期,类似于以下内容: + +```json +{ + "_index": "apisix-2025.01.13", + "_type": "logs", Review Comment: 示例输出中出现 `_type: "logs"`,但 elasticsearch-logger 并不会设置自定义 type;对旧版本 ES 仅会内部使用 `_doc`,而 ES 7.x 已移除 mapping types。建议调整示例输出为实际 Elasticsearch 返回/展示的字段,或移除 `_type`。 ```suggestion ``` ########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -447,3 +453,66 @@ As a workaround, you may be able to use the NGINX variable `$request_body` in th ``` ::: + +### Include Request Date in Elasticsearch Index + +The following example demonstrates how you can configure the `elasticsearch-logger` Plugin to include the request date in the Elasticsearch index name. + +Create a Route with `elasticsearch-logger` as follows: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "elasticsearch-logger-route", + "uri": "/anything", + "plugins": { + "elasticsearch-logger": { + "endpoint_addrs": ["http://elasticsearch:9200"], + "field": { + "index": "apisix-{%Y.%m.%d}", + "type": "logs" + } Review Comment: This new example relies on `field.index` supporting `{%Y.%m.%d}` date expansion, but the current plugin sends `conf.field.index` verbatim (no time-format interpolation). As written, Elasticsearch would receive the literal index name `apisix-{%Y.%m.%d}`. Please remove/adjust this example or add the corresponding interpolation support in the plugin. ########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -40,21 +40,22 @@ The `elasticsearch-logger` Plugin pushes request and response logs in batches to | Name | Type | Required | Default | Description | | ------------- | ------- | -------- | --------------------------- | ------------------------------------------------------------ | | endpoint_addrs | array[string] | True | | Elasticsearch API endpoint addresses. If multiple endpoints are configured, they will be written randomly. | -| field | object | True | | Elasticsearch `field` configuration. | -| field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). | +| field | object | True | | Elasticsearch field configuration. | +| field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). Supports the configuration of a [lua time format](https://www.lua.org/pil/22.1.html) in curly brackets to include the current date, such as `service-{%Y-%m-%d}`. | +| field.type | string | False | | Elasticsearch [_type field](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-type-field.html#mapping-type-field). | | log_format | object | False | | Custom log format as key-value pairs in JSON. Values support strings and nested objects (up to five levels deep; deeper fields are truncated). Within strings, [APISIX](../apisix-variable.md) or [NGINX variables](http://nginx.org/en/docs/varindex.html) can be referenced by prefixing with `$`. | -| auth | array | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) configuration. | -| auth.username | string | True | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) username. | -| auth.password | string | True | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) password. | -| headers | object | False | | Custom headers to send with requests as key-value pairs. For example: `{"Authorization": "Bearer token", "X-API-Key": "key"}`. | +| auth | object | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) configuration. | +| auth.username | string | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) username. | +| auth.password | string | False | | Elasticsearch [authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) password. The secret is encrypted with AES before being stored in etcd. | +| headers | object | False | | Custom HTTP request headers to include in requests sent to Elasticsearch, as key-value pairs. Can be used as an alternative or complement to `auth` for authentication and other purposes. Available in APISIX from 3.16.0. | | ssl_verify | boolean | False | true | If true, perform SSL verification. | | timeout | integer | False | 10 | Elasticsearch send data timeout in seconds. | | include_req_body | boolean | False | false | If true, include the request body in the log. Note that if the request body is too big to be kept in the memory, it can not be logged due to NGINX's limitations. | | include_req_body_expr | array[array] | False | | An array of one or more conditions in the form of [lua-resty-expr](https://github.com/api7/lua-resty-expr). Used when the `include_req_body` is true. Request body would only be logged when the expressions configured here evaluate to true. | -| max_req_body_bytes | integer | False | 524288 | Request bodies within this size will be logged, if the size exceeds the configured value it will be truncated before logging. | +| max_req_body_bytes | integer | False | 524288 | >=1 | Request bodies within this size will be logged, if the size exceeds the configured value it will be truncated before logging. | | include_resp_body | boolean | False | false | If true, include the response body in the log. | | include_resp_body_expr | array[array] | False | | An array of one or more conditions in the form of [lua-resty-expr](https://github.com/api7/lua-resty-expr). Used when the `include_resp_body` is true. Response body would only be logged when the expressions configured here evaluate to true. | -| max_resp_body_bytes | integer | False | 524288 | Response bodies within this size will be logged, if the size exceeds the configured value it will be truncated before logging. | +| max_resp_body_bytes | integer | False | 524288 | >=1 | Response bodies within this size will be logged, if the size exceeds the configured value it will be truncated before logging. | Review Comment: The table row for `max_req_body_bytes`/`max_resp_body_bytes` adds an extra `>=1` column, but the Attributes table only has 5 columns. This breaks the Markdown table rendering. Either add a dedicated “Valid values” column to the header/separator, or move `>=1` into the Description cell. ########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -447,3 +453,66 @@ As a workaround, you may be able to use the NGINX variable `$request_body` in th ``` ::: + +### Include Request Date in Elasticsearch Index + +The following example demonstrates how you can configure the `elasticsearch-logger` Plugin to include the request date in the Elasticsearch index name. + +Create a Route with `elasticsearch-logger` as follows: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "elasticsearch-logger-route", + "uri": "/anything", + "plugins": { + "elasticsearch-logger": { + "endpoint_addrs": ["http://elasticsearch:9200"], + "field": { + "index": "apisix-{%Y.%m.%d}", + "type": "logs" + } + } + }, + "upstream": { + "nodes": { + "httpbin.org:80": 1 + }, + "type": "roundrobin" + } + }' +``` + +The `index` field uses a [lua time format](https://www.lua.org/pil/22.1.html) in curly brackets to append the current year, month, and date to the index name. + +Send a request to the Route to generate a log entry: + +```shell +curl -i "http://127.0.0.1:9080/anything" +``` + +You should receive an `HTTP/1.1 200 OK` response. + +Navigate to the Kibana dashboard on [localhost:5601](http://localhost:5601) and under __Discover__ tab, create a new index pattern `apisix*` to fetch the data from Elasticsearch. Once configured, navigate back to the __Discover__ tab and you should see a log generated with an index name containing the current date, similar to the following: + +```json +{ + "_index": "apisix-2025.01.13", + "_type": "logs", Review Comment: This example output includes `_type: "logs"`, but elasticsearch-logger doesn’t set a custom type (for ES 7.x types are removed; for older ES it uses `_doc`). Please adjust the sample output to match real Elasticsearch responses, or omit `_type` entirely. ```suggestion ``` ########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -40,21 +40,22 @@ The `elasticsearch-logger` Plugin pushes request and response logs in batches to | Name | Type | Required | Default | Description | | ------------- | ------- | -------- | --------------------------- | ------------------------------------------------------------ | | endpoint_addrs | array[string] | True | | Elasticsearch API endpoint addresses. If multiple endpoints are configured, they will be written randomly. | -| field | object | True | | Elasticsearch `field` configuration. | -| field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). | +| field | object | True | | Elasticsearch field configuration. | +| field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). Supports the configuration of a [lua time format](https://www.lua.org/pil/22.1.html) in curly brackets to include the current date, such as `service-{%Y-%m-%d}`. | +| field.type | string | False | | Elasticsearch [_type field](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-type-field.html#mapping-type-field). | Review Comment: Docs claim `field.index` supports Lua time formatting in `{...}` and introduce `field.type`, but the plugin schema/code only uses `conf.field.index` as a literal string and does not read `field.type` (only sets `_type = "_doc"` internally for ES 5/6). Please remove/adjust these statements or implement the feature in the plugin to match the docs. ```suggestion | field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). | ``` ########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -151,6 +153,7 @@ Navigate to the Kibana dashboard on [localhost:5601](http://localhost:5601) and ```json { "_index": "gateway", + "_type": "logs", Review Comment: The sample Elasticsearch document shows `_type: "logs"`, but APISIX’s elasticsearch-logger does not set a custom type; for older ES it uses `_doc`, and for ES 7.x types are removed. Please update the example output to match actual Elasticsearch responses for the supported versions. ```suggestion ``` ########## docs/zh/latest/plugins/elasticsearch-logger.md: ########## @@ -446,3 +453,66 @@ curl -i "http://127.0.0.1:9080/anything" -X POST -d '{"env": "dev"}' ``` ::: + +### 在 Elasticsearch 索引中包含请求日期 + +以下示例演示了如何配置 `elasticsearch-logger` 插件,以在 Elasticsearch 索引名称中包含请求日期。 + +使用 `elasticsearch-logger` 创建路由,如下所示: + +```shell +curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "id": "elasticsearch-logger-route", + "uri": "/anything", + "plugins": { + "elasticsearch-logger": { + "endpoint_addrs": ["http://elasticsearch:9200"], + "field": { + "index": "apisix-{%Y.%m.%d}", + "type": "logs" + } Review Comment: 新增的“包含请求日期”示例依赖 `field.index` 支持 `{%Y.%m.%d}` 的日期插值,但当前插件会原样发送 `conf.field.index`(不做时间格式替换)。按当前实现,索引名会变成字面量 `apisix-{%Y.%m.%d}`。请删除/修正该示例,或在插件中实现对应插值能力。 ########## docs/zh/latest/plugins/elasticsearch-logger.md: ########## @@ -40,20 +40,23 @@ description: elasticsearch-logger Plugin 将请求和响应日志批量推送到 | 名称 | 类型 | 必选项 | 默认值 | 描述 | | ------------- | ------- | -------- | -------------------- | ------------------------------------------------------------ | -| endup_addrs | array[string] | 是 | | Elasticsearch API 端点地址。如果配置了多个端点,则会随机写入。 | -| field | object | 是 | | Elasticsearch `field` 配置。 | -| field.index | string | 是 | | Elasticsearch [_index 字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field)。 | +| endpoint_addrs | array[string] | 是 | | Elasticsearch API 端点地址。如果配置了多个端点,则会随机写入。 | +| field | object | 是 | | Elasticsearch 字段配置。 | +| field.index | string | 是 | | Elasticsearch [_index 字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field)。支持在花括号中使用 [lua 时间格式](https://www.lua.org/pil/22.1.html) 来包含当前日期,例如 `service-{%Y-%m-%d}`。 | +| field.type | string | 否 | | Elasticsearch [_type 字段](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-type-field.html#mapping-type-field)。 | | log_format | object | 否 | | 自定义日志格式以 JSON 的键值对声明。值支持字符串和嵌套对象(最多五层,超出部分将被截断)。字符串中可通过 `$` 前缀引用 [APISIX](../apisix-variable.md) 或 [NGINX 变量](http://nginx.org/en/docs/varindex.html)。 | -| auth | array | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 配置。 | -| auth.username | string | 是 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 用户名。 | -| auth.password | string | 是 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 密码。 | -| headers | object | 否 | | 自定义请求标头,以键值对形式配置。例如 `{"Authorization": "Bearer token", "X-API-Key": "key"}`。 | +| auth | object | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 配置。 | +| auth.username | string | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 用户名。 | +| auth.password | string | 否 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 密码。该密钥在存储到 etcd 之前会使用 AES 加密。 | Review Comment: 表格里 `auth.username`/`auth.password` 标为“否”,但插件 schema 要求当 `auth` 存在时这两个字段必须成对同时配置(只配一个会校验失败)。建议在表格中注明“当配置 `auth` 时必填”,避免读者误配。 ```suggestion | auth.username | string | 当配置 `auth` 时必填 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 用户名。需与 `auth.password` 成对配置。 | | auth.password | string | 当配置 `auth` 时必填 | | Elasticsearch [身份验证](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html) 密码。需与 `auth.username` 成对配置。该密钥在存储到 etcd 之前会使用 AES 加密。 | ``` ########## docs/zh/latest/plugins/elasticsearch-logger.md: ########## @@ -124,7 +127,8 @@ curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \ "elasticsearch-logger": { "endpoint_addrs": ["http://elasticsearch:9200"], "field": { - "index": "gateway" + "index": "gateway", + "type": "logs" Review Comment: 示例里配置了 `field.type: "logs"`,但插件不会使用该值来构造 bulk index action(ES 7.x 也不支持自定义 `_type`)。这会让读者误以为 `type` 会生效,建议从示例中移除该字段。 ```suggestion "index": "gateway" ``` ########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -125,7 +126,8 @@ curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \ "elasticsearch-logger": { "endpoint_addrs": ["http://elasticsearch:9200"], "field": { - "index": "gateway" + "index": "gateway", + "type": "logs" Review Comment: The examples configure `field.type: "logs"`, but the plugin does not use this value when constructing bulk index actions (and for ES 7.x `_type` is not configurable). This can mislead users into thinking the `type` setting has an effect—consider removing it from the examples. ```suggestion "index": "gateway" ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
