Skip to content

feat: implement datastream support on elasticsearch-logger plugin#13102

Open
jr-instantsystem wants to merge 13 commits intoapache:masterfrom
jr-instantsystem:feat/elastisearch-logger-datastream-suppot
Open

feat: implement datastream support on elasticsearch-logger plugin#13102
jr-instantsystem wants to merge 13 commits intoapache:masterfrom
jr-instantsystem:feat/elastisearch-logger-datastream-suppot

Conversation

@jr-instantsystem
Copy link

@jr-instantsystem jr-instantsystem commented Mar 18, 2026

Description

The current plugin allows to push messages to raw indices in ElasticSearch, using the "POST _bulk" endpoint, with the "_index" action.
It not compatible with DataSteams according to https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk, where action have to be "_create" to push on DataStream.

The PR add a second plugin param for a datastream name. The user must choose between "index name" or "datastream name" to define the method used to push to ElasticSearch.

Tested on 3.12

Which issue(s) this PR fixes:

N/A

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Mar 18, 2026
}
}
}
else if conf.field.datastream then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if conf.field.datastream then
elseif conf.field.datastream then

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

Comment on lines +222 to +224
else
core.log.error("Unsupported field configuration")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is unnecessary. The schema's oneOf constraint ensures that at least one of the index and datastream is set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code removed

@Baoyuantop Baoyuantop changed the title Implement datastream support on elasticsearch-logger plugin feat: implement datastream support on elasticsearch-logger plugin Mar 18, 2026
@Baoyuantop Baoyuantop requested a review from Copilot March 18, 2026 10:06
Copy link
Contributor

@Baoyuantop Baoyuantop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to add tests for this feature.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the elasticsearch-logger plugin to support writing logs to either a classic Elasticsearch index or a DataStream target, and aligns the plugin documentation with the new configuration options.

Changes:

  • Extend the plugin schema to allow configuring either field.index or field.datastream (mutually exclusive).
  • Update bulk action generation to emit index vs create actions depending on the configured target.
  • Document the new field.datastream attribute and update notes around required field configuration.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/en/latest/plugins/elasticsearch-logger.md Documents field.index / field.datastream options and updates notes about required configuration.
apisix/plugins/elasticsearch-logger.lua Adds schema support and runtime logic to generate bulk entries for index vs datastream targets.
Comments suppressed due to low confidence (1)

apisix/plugins/elasticsearch-logger.lua:231

  • When field.datastream is used, body is built with a create action and has no body.index, but the ES 5/6 compatibility block unconditionally writes body.index._type. This will throw a runtime error; set _type on the actual action present (e.g., body.index vs body.create) or restructure to avoid accessing body.index when using datastream.
    -- for older version type is required
    if conf._version == "6" or conf._version == "5" then
        body.index._type = "_doc"
    end

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +60 to +62
NOTE:
- `encrypt_fields = {"auth.password"}` is also defined in the schema, which means that the field will be stored encrypted in etcd. See [encrypted storage fields](../plugin-develop.md#encrypted-storage-fields).
- One of `field.index` or `field.datastream` must be set.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants