membphis commented on code in PR #12364: URL: https://github.com/apache/apisix/pull/12364#discussion_r2161741034
########## apisix/plugins/elasticsearch-logger.lua: ########## @@ -156,12 +204,30 @@ local function send_to_elasticsearch(conf, entries) else selected_endpoint_addr = conf.endpoint_addrs[math_random(#conf.endpoint_addrs)] end + if not conf._version then + local major_version, err = get_es_major_version(selected_endpoint_addr, conf) + if err then + return false, str_format("failed to get Elasticsearch version: %s", err) + end + conf._version = major_version + end local uri = selected_endpoint_addr .. "/_bulk" local body = core.table.concat(entries, "") local headers = { - ["Content-Type"] = "application/x-ndjson;compatible-with=7", - ["Accept"] = "application/vnd.elasticsearch+json;compatible-with=7" + ["Content-Type"] = "application/x-ndjson", + ["Accept"] = "application/vnd.elasticsearch+json" } + if conf._version == "8" then + headers["Content-Type"] = headers["Content-Type"] .. compat_header_7 + headers["Accept"] = headers["Accept"] .. compat_header_7 + elseif conf._version == "9" then + headers["Content-Type"] = headers["Content-Type"] .. compat_header_8 + headers["Accept"] = headers["Accept"] .. compat_header_8 + if conf.field.type then + core.log.warn("type is not supported in Elasticsearch 9, removing `type`") Review Comment: I think we should use error log level -- 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: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org