Baoyuantop commented on code in PR #13102:
URL: https://github.com/apache/apisix/pull/13102#discussion_r2958583788
##########
apisix/plugins/elasticsearch-logger.lua:
##########
@@ -202,11 +206,21 @@ end
local function get_logger_entry(conf, ctx)
local entry = log_util.get_log_entry(plugin_name, conf, ctx)
- local body = {
- index = {
- _index = conf.field.index
+ local body
+ if conf.field.index then
+ body = {
+ index = {
+ _index = conf.field.index
+ }
}
- }
+ elseif conf.field.datastream then
+ body = {
+ create = {
+ _index = conf.field.datastream
+ }
+ }
+ end
+
-- for older version type is required
if conf._version == "6" or conf._version == "5" then
body.index._type = "_doc"
Review Comment:
When datastream is configured, the body only contains the "create" key, not
the "index" key. For version compatibility, accessing `nil.index` with
`body.index._type = "_doc"` will trigger a runtime error: "attempt to index a
nil value".
--
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]