PHPackages                             rajmundtoth0/laravel-auditing-elasticsearch-driver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. rajmundtoth0/laravel-auditing-elasticsearch-driver

ActivePackage[Database &amp; ORM](/categories/database)

rajmundtoth0/laravel-auditing-elasticsearch-driver
==================================================

An Elasticsearch driver for the owen-it/laravel-auditing package.

2.0(4mo ago)595.1k↑10.7%1MITPHPPHP &gt;=8.2CI passing

Since May 26Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/rajmundtoth0/laravel-auditing-elasticsearch-driver)[ Packagist](https://packagist.org/packages/rajmundtoth0/laravel-auditing-elasticsearch-driver)[ RSS](/packages/rajmundtoth0-laravel-auditing-elasticsearch-driver/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (22)Versions (34)Used By (0)

[![Version](https://camo.githubusercontent.com/37170464d975534cb3f34d65e4541203a97521f40db18d04edbd03bc83f81b90/68747470733a2f2f706f7365722e707567782e6f72672f72616a6d756e64746f7468302f6c61726176656c2d6175646974696e672d656c61737469637365617263682d6472697665722f76657273696f6e)](https://packagist.org/packages/rajmundtoth0/laravel-auditing-elasticsearch-driver)[![codecov](https://camo.githubusercontent.com/e4cafc063953a1a91bcfcdc81a4a094a09bd185381a70805cdafb142072d16a0/68747470733a2f2f636f6465636f762e696f2f67682f72616a6d756e64746f7468302f6c61726176656c2d6175646974696e672d656c61737469637365617263682d6472697665722f67726170682f62616467652e7376673f746f6b656e3d58365833554550373742)](https://codecov.io/gh/rajmundtoth0/laravel-auditing-elasticsearch-driver)[![PHPStan](https://camo.githubusercontent.com/6e3a30e41775db9d2d50ecd44a30d4611a185a180e6147c9c5a985eeeab96874/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c5f4d41582d627269676874677265656e)](https://camo.githubusercontent.com/6e3a30e41775db9d2d50ecd44a30d4611a185a180e6147c9c5a985eeeab96874/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c5f4d41582d627269676874677265656e)[![Build](https://github.com/rajmundtoth0/laravel-auditing-elasticsearch-driver/actions/workflows/php.yml/badge.svg)](https://github.com/rajmundtoth0/laravel-auditing-elasticsearch-driver/actions/workflows/php.yml)[![Codacy Badge](https://camo.githubusercontent.com/3f26b53c4071eda8368c31f9fcb0e406df7504e59a13c70919a63d6f3ad64dfd/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3136646235643538353636633437616439396261633062633133373339393764)](https://app.codacy.com?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![PHP Version Require](https://camo.githubusercontent.com/65aaf6854e931ea7b5e476140aa9948be8343b5f4f44d223890cf0a1d40ae7b8/68747470733a2f2f706f7365722e707567782e6f72672f72616a6d756e64746f7468302f6c61726176656c2d6175646974696e672d656c61737469637365617263682d6472697665722f726571756972652f706870)](https://packagist.org/packages/rajmundtoth0/laravel-auditing-elasticsearch-driver)[![License](https://camo.githubusercontent.com/93faf6f09ccde1184f253a55ff58ff399e2f0f94f8ec04e033babdf7e6cab2f8/68747470733a2f2f706f7365722e707567782e6f72672f72616a6d756e64746f7468302f6c61726176656c2d6175646974696e672d656c61737469637365617263682d6472697665722f6c6963656e7365)](https://packagist.org/packages/rajmundtoth0/laravel-auditing-elasticsearch-driver)[![Total Downloads](https://camo.githubusercontent.com/c061f0109811e171ca6943d439de1b41f46486639be157971029ff886e6c82c8/68747470733a2f2f706f7365722e707567782e6f72672f72616a6d756e64746f7468302f6c61726176656c2d6175646974696e672d656c61737469637365617263682d6472697665722f646f776e6c6f616473)](https://packagist.org/packages/rajmundtoth0/laravel-auditing-elasticsearch-driver)[![Latest Version on Packagist](https://camo.githubusercontent.com/807cb9d18a4a7122894e3471d6c722ea0da025d3a1327c37b7a80602838f2a69/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616a6d756e64746f7468302f6c61726176656c2d6175646974696e672d656c61737469637365617263682d6472697665722e737667)](https://packagist.org/packages/rajmundtoth0/laravel-auditing-elasticsearch-driver)

Laravel Auditing Elasticsearch Driver
=====================================

[](#laravel-auditing-elasticsearch-driver)

Elasticsearch driver for [Laravel Auditing](https://laravel-auditing.com/), with support for both classic indices and Elasticsearch data streams.

Highlights
----------

[](#highlights)

- Index or data stream storage mode (`index` / `data_stream`)
- Optional ILM lifecycle policy + index template management for data streams
- Queue-aware indexing
- Typed configuration and strict static analysis support
- CI coverage for feature and integration test suites

Requirements
------------

[](#requirements)

DependencySupportedPHP`>=8.2`Laravel`^11 | ^12`elasticsearch/elasticsearch`^8.0 | ^9.0`owen-it/laravel-auditing`^13.0 | ^14.0`Installation
------------

[](#installation)

```
composer require rajmundtoth0/laravel-auditing-elasticsearch-driver
```

If you need to publish package config:

```
php artisan vendor:publish --provider="rajmundtoth0\\AuditDriver\\ElasticsearchAuditingServiceProvider"
```

Set Laravel Auditing to use this driver in `config/audit.php`:

```
'driver' => rajmundtoth0\AuditDriver\Services\ElasticsearchAuditService::class,
```

Configuration
-------------

[](#configuration)

Use the `drivers.elastic` section in `config/audit.php`:

```
'elastic' => [
    'hosts' => [env('AUDIT_HOST', 'http://0.0.0.0:9200')],
    'userName' => env('ELASTIC_AUDIT_USER', 'elastic'),
    'password' => env('ELASTIC_AUDIT_PASSWORD', 'a_very_strong_password'),
    'useBasicAuth' => (bool) env('AUDIT_BASIC_AUTH', true),
    'useCaCert' => (bool) env('AUDIT_USE_CERT', true),
    'certPath' => env('AUDIT_CERT_PATH', ''),

    'index' => env('AUDIT_INDEX', 'laravel_auditing'),
    'storageMode' => env('AUDIT_STORAGE_MODE', 'index'), // index|data_stream
    'definitions' => [
        'settings' => [
            'path' => env('AUDIT_SETTINGS_PATH', ''),
        ],
        'mappings' => [
            'path' => env('AUDIT_MAPPINGS_PATH', ''),
        ],
        'lifecyclePolicy' => [
            'path' => env('AUDIT_LIFECYCLE_POLICY_PATH', ''),
        ],
    ],

    'dataStream' => [
        'templateName' => env('AUDIT_DATA_STREAM_TEMPLATE_NAME', env('AUDIT_INDEX', 'laravel_auditing').'_template'),
        'indexPattern' => env('AUDIT_DATA_STREAM_INDEX_PATTERN', env('AUDIT_INDEX', 'laravel_auditing').'*'),
        'templatePriority' => (int) env('AUDIT_DATA_STREAM_TEMPLATE_PRIORITY', 100),
        'lifecyclePolicyName' => env('AUDIT_DATA_STREAM_LIFECYCLE_POLICY', ''),
        'pipeline' => env('AUDIT_DATA_STREAM_PIPELINE', ''),
    ],
    'singleWriteRetry' => [
        'enabled' => (bool) env('AUDIT_SINGLE_WRITE_RETRY_ENABLED', true),
        'maxAttempts' => (int) env('AUDIT_SINGLE_WRITE_RETRY_MAX_ATTEMPTS', 3),
        'initialBackoffMs' => (int) env('AUDIT_SINGLE_WRITE_RETRY_INITIAL_BACKOFF_MS', 100),
        'maxBackoffMs' => (int) env('AUDIT_SINGLE_WRITE_RETRY_MAX_BACKOFF_MS', 2000),
        'backoffMultiplier' => (float) env('AUDIT_SINGLE_WRITE_RETRY_BACKOFF_MULTIPLIER', 2.0),
        'jitterMs' => (int) env('AUDIT_SINGLE_WRITE_RETRY_JITTER_MS', 25),
    ],
],
```

### JSON Definitions

[](#json-definitions)

Default JSON definitions are stored in:

- `resources/elasticsearch/settings.json`
- `resources/elasticsearch/mappings.json`
- `resources/elasticsearch/lifecycle-policy.json`

`mappings.json` defines `old_values` and `new_values` as dynamic objects, so model-specific audit keys can be indexed without predefined fields.

The driver resolves each definition in this order:

1. File path from `definitions.*.path`
2. Package default JSON file in `resources/elasticsearch/`

File path override example:

```
'definitions' => [
    'settings' => [
        'path' => base_path('infra/elasticsearch/settings.json'),
    ],
    'mappings' => [
        'path' => base_path('infra/elasticsearch/mappings.json'),
    ],
    'lifecyclePolicy' => [
        'path' => base_path('infra/elasticsearch/lifecycle.json'),
    ],
],
```

### Storage Mode Behavior

[](#storage-mode-behavior)

- `index` mode: setup creates index + write alias.
- `data_stream` mode: setup creates/updates template and optional ILM policy; Elasticsearch auto-creates the data stream on first write.

Note: in `data_stream` mode, the driver auto-populates `@timestamp` if missing.

### Single-Write Retries

[](#single-write-retries)

Single document writes use retries with exponential backoff for transient failures (`408`, `429`, `5xx`, node-unavailable).

Retry timing values are configured through `singleWriteRetry.*` in `config/audit.php`.

- `maxAttempts`: total attempts, including the first call
- `initialBackoffMs`: delay before first retry
- `backoffMultiplier`: exponential factor per retry
- `maxBackoffMs`: upper bound for delay
- `jitterMs`: random `+/-` jitter to avoid synchronized retry spikes

In `data_stream` mode, `op_type=create` conflicts (`409`) are treated as success to keep retries idempotent.

Setup Command
-------------

[](#setup-command)

Run once after configuration changes:

```
php artisan es-audit-log:setup
```

Lifecycle Policy Example
------------------------

[](#lifecycle-policy-example)

If you want the package to create/update an ILM policy, set `lifecyclePolicyName` and provide the policy through `definitions.lifecyclePolicy` (JSON or file path):

```
'dataStream' => [
    'lifecyclePolicyName' => 'audits-hot-delete',
],
'definitions' => [
    'lifecyclePolicy' => [
        'path' => base_path('infra/elasticsearch/lifecycle.json'),
    ],
],
```

Lifecycle definitions are validated at boot and must contain `policy.phases` as a non-empty object.

Usage
-----

[](#usage)

Add `OwenIt\Auditing\Auditable` to your model as usual.

To read Elasticsearch audit logs from your model:

- `$model->audit_log`
- `$model->elasticsearchAuditLog($page, $pageSize, $sort)`

These methods are provided by [`ElasticSearchAuditable`](src/Traits/ElasticSearchAuditable.php).

Queue Support
-------------

[](#queue-support)

If `drivers.queue.enabled` is `true`, audit documents are queued and indexed asynchronously.

Testing
-------

[](#testing)

```
composer test
composer analyse
```

Integration tests (against real Elasticsearch):

```
AUDIT_RUN_INTEGRATION_TESTS=true AUDIT_INTEGRATION_HOST=http://localhost:9200 composer test-integration
```

Contributing
------------

[](#contributing)

Open pull requests against the `master` branch.

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance80

Actively maintained with recent releases

Popularity38

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 90.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~54 days

Total

21

Last Release

125d ago

Major Versions

1.4.4 → v2.0.0.x-dev2026-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5e554067d29bb565ced3d192bcfd536c8d84beb11b5286a227c5142361b3d99?d=identicon)[RajmundT](/maintainers/RajmundT)

---

Top Contributors

[![rajmundtoth0](https://avatars.githubusercontent.com/u/115630432?v=4)](https://github.com/rajmundtoth0 "rajmundtoth0 (58 commits)")[![AJenbo](https://avatars.githubusercontent.com/u/204594?v=4)](https://github.com/AJenbo "AJenbo (6 commits)")

---

Tags

auditaudit-logelasticsearchelkelk-stackeslaravellaravel-auditingloggingobservabilityphploglaravelloggingelasticsearcheloquenttrackingAuditobserveres

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rajmundtoth0-laravel-auditing-elasticsearch-driver/health.svg)

```
[![Health](https://phpackages.com/badges/rajmundtoth0-laravel-auditing-elasticsearch-driver/health.svg)](https://phpackages.com/packages/rajmundtoth0-laravel-auditing-elasticsearch-driver)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k36.8M157](/packages/owen-it-laravel-auditing)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[betapeak/laravel-auditing-filesystem

A filesystem driver for the owen-it/laravel-auditing package. Allows storage of the audits in CSV files, across all registered Laravel disks.

166.5k](/packages/betapeak-laravel-auditing-filesystem)[altek/accountant

The auditing &amp; accountability package for Laravel's Eloquent ORM.

921.0M4](/packages/altek-accountant)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
