diff --git a/apisix/plugins/elasticsearch-logger.lua b/apisix/plugins/elasticsearch-logger.lua index de29da2e0184..81fdc157d43b 100644 --- a/apisix/plugins/elasticsearch-logger.lua +++ b/apisix/plugins/elasticsearch-logger.lua @@ -138,7 +138,10 @@ local function send_to_elasticsearch(conf, entries) end local uri = selected_endpoint_addr .. "/_bulk" local body = core.table.concat(entries, "") - local headers = {["Content-Type"] = "application/x-ndjson"} + local headers = { + ["Content-Type"] = "application/x-ndjson;compatible-with=7", + ["Accept"] = "application/vnd.elasticsearch+json;compatible-with=7" + } if conf.auth then local authorization = "Basic " .. ngx.encode_base64( conf.auth.username .. ":" .. conf.auth.password diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml index 13a34e3908f7..afdb3817554d 100644 --- a/ci/pod/docker-compose.plugin.yml +++ b/ci/pod/docker-compose.plugin.yml @@ -201,7 +201,7 @@ services: # Elasticsearch Logger Service elasticsearch-noauth: - image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1 + image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 restart: unless-stopped ports: - "9200:9200" @@ -212,18 +212,16 @@ services: xpack.security.enabled: 'false' elasticsearch-auth: - image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1 + image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0 restart: unless-stopped ports: - "9201:9201" - - "9301:9301" environment: ES_JAVA_OPTS: -Xms512m -Xmx512m discovery.type: single-node ELASTIC_USERNAME: elastic ELASTIC_PASSWORD: 123456 http.port: 9201 - transport.tcp.port: 9301 xpack.security.enabled: 'true' diff --git a/t/plugin/elasticsearch-logger.t b/t/plugin/elasticsearch-logger.t index ba9b6bfd9c84..2a2d0996dc9e 100644 --- a/t/plugin/elasticsearch-logger.t +++ b/t/plugin/elasticsearch-logger.t @@ -668,3 +668,55 @@ hello world --- wait: 2 --- error_log check elasticsearch custom body success + + + +=== TEST 17: using unsupported field (type) for elasticsearch v8 should work normally +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, { + uri = "/hello", + upstream = { + type = "roundrobin", + nodes = { + ["127.0.0.1:1980"] = 1 + } + }, + plugins = { + ["elasticsearch-logger"] = { + endpoint_addr = "http://127.0.0.1:9201", + field = { + index = "services", + type = "collector" + }, + auth = { + username = "elastic", + password = "123456" + }, + batch_max_size = 1, + inactive_timeout = 1 + } + } + }) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- response_body +passed + + + +=== TEST 18: test route (auth success) +--- request +GET /hello +--- wait: 2 +--- response_body +hello world +--- no_error_log +Action/metadata line [1] contains an unknown parameter [_type]