Use Elasticsearch Datastreams
masterFor Elasticsearch 7.9 and higher, you can use Datastreams by setting the dataStream option to true.
When enabled:
- Bulk indexing uses the
createoperation instead ofindex. - The default naming convention is
logs-*-*, which automatically matches built-in Elasticsearch Index templates and ILM (Index Lifecycle Management) policies. - The default datastream name is
logs-app-default.
To use a custom name with the built-in template and ILM policy, set the index option to a value that matches the logs-*-* pattern.
Note on Fallbacks:
If dataStream: true is enabled, but you are using Elasticsearch < 7.9, OR you have provided a custom index name that does not match logs-*-* (and no custom matching template exists in Elasticsearch), the library will fall back to creating a normal index instead of a datastream.
// Example configuration for Datastreams
{
dataStream: true,
index: 'logs-my-app-production' // Must match logs-*-* to use built-in templates
}