PHPackages                             subsan/codeception-module-elasticsearch - 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. [Search &amp; Filtering](/categories/search)
4. /
5. subsan/codeception-module-elasticsearch

ActiveLibrary[Search &amp; Filtering](/categories/search)

subsan/codeception-module-elasticsearch
=======================================

Elasticsearch module for Codeception

v1.0.1(4y ago)25632MITPHPPHP ^7.1|^8.0

Since Oct 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/subsan/codeception-module-elasticsearch)[ Packagist](https://packagist.org/packages/subsan/codeception-module-elasticsearch)[ Docs](https://github.com/subsan/codeception-module-elasticsearch)[ RSS](/packages/subsan-codeception-module-elasticsearch/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (5)Used By (0)

Elasticsearch module for Codeception
====================================

[](#elasticsearch-module-for-codeception)

Connects to [Elasticsearch](https://www.elastic.co/) using [elasticsearch/elasticsearch](https://github.com/elastic/elasticsearch-php) official php client.

Can cleanup by delete all or listed in config indexes after each test or test suite run. Can restore snapshot from fs before each test or test suite.

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require --dev "subsan/codeception-module-elasticsearch"

```

### Elasticsearch config

[](#elasticsearch-config)

If You need to use snapshots You need add to elasticsearch config path to snapshots

elasticsearch.yml:

```
path.repo: ["/PATH_TO_YOUR_PROJECT/tests/_data/elasticsearch/"]

```

Usage
-----

[](#usage)

### Config

[](#config)

- hosts *required* - elasticsearch hosts
- snapshotPath - path to snapshot
- snapshotName - snapshot name
- compressedSnapshot: true - is snapshot compressed
- populateBeforeTest: false - whether the snapshot should be loaded before the test suite is started
- populateBeforeSuite: false - whether the snapshot should be reloaded before each test
- cleanup: false - delete indexes from list \[indexes\] or all (if indexes null) after after each test or test suite finished
- indexes: null - list of indexes to delete after after each test or test suite finished.

### Example (`acceptance.suite.yml`)

[](#example-acceptancesuiteyml)

```
   modules:
        - Elasticsearch:
            hosts:
              - host: 'localhost'
                port: 9200
                user: 'elastic'
                pass: ''
            snapshotPath: 'tests/_data/elasticsearch'
            snapshotName: 'snapshot_name'
            compressedSnapshot: true
            populateBeforeTest: true
            populateBeforeSuite: true
            cleanup: true
            indexes:
              - index1
              - index2
```

### Create snapshot example:

[](#create-snapshot-example)

```
$hosts = \Jam\Core\Core::getInstance()->config()->elasticsearch()::[YOUR_HOSTS];
$raw   = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();

// create repo
$repoParams = [
    'repository' => 'codeception',
    'body'       => [
        'type'     => 'fs',
        'settings' => [
            'location' => '/PATH_TO_YOUR_PROJECT/tests/_data/elasticsearch',
            'compress' => true
        ]
    ]
];
$raw->snapshot()->createRepository($repoParams);

$restoreParams = [
    'repository'          => 'codeception',
    'snapshot'            => 'snapshotName',
    'wait_for_completion' => true,
    'body'                => [
        "indices"              => "INDEX_1,INDEX_2",
        "include_global_state" => false
    ]
];
$raw->snapshot()->create($restoreParams);
```

### Public Properties

[](#public-properties)

- **elasticsearchClient** - instance of Elasticsearch\\Client

### Actions

[](#actions)

#### seeDocumentInElasticsearch

[](#seedocumentinelasticsearch)

Asserts that a document with the given id exists in the index. Provide index name and document id.

```
$I->seeDocumentInElasticsearch('testIndex', 111);
```

- `param string` $index
- `param string|int` $id

#### dontSeeDocumentInElasticsearch

[](#dontseedocumentinelasticsearch)

Effect is opposite to -&gt;seeDocumentInElasticsearch Asserts there is no document with the given id exists in the index. Provide index name and document id.

```
$I->dontSeeDocumentInElasticsearch('testIndex', 222);
```

- `param string` $index
- `param string|int` $id

#### grabDocumentFromElasticsearch

[](#grabdocumentfromelasticsearch)

Returns response of get document [function](https://github.com/elastic/elasticsearch-php#get-a-document)

```
$response = $I->grabDocumentFromElasticsearch('testIndex', 111);
print_r($response);
```

The response contains some metadata (index, version, etc.) as well as a \_source field, which is the original document that you sent to Elasticsearch.

```
Array
(
    [_index] => testIndex
    [_type] => _doc
    [_id] => 111
    [_version] => 1
    [_seq_no] => 4205
    [_primary_term] => 1
    [found] => 1
    [_source] => Array
        (
            [testField] => abc
        )
```

- `param string` $index
- `param string|int` $id
- `return array` $response

#### haveInElasticsearch

[](#haveinelasticsearch)

Inserts document into an index

```
$item = [
    'testField' => 'abc'
];
$I->haveInElasticsearch('testIndex', 222, $item);
```

- `param string` $index
- `param string|int` $id
- `param array` $body
- `return array` $response

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~207 days

Total

4

Last Release

1468d ago

PHP version history (2 changes)v1.0.0PHP ^7.1

v1.0.1PHP ^7.1|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1093589?v=4)[subsan](/maintainers/subsan)[@subsan](https://github.com/subsan)

---

Top Contributors

[![subsan](https://avatars.githubusercontent.com/u/1093589?v=4)](https://github.com/subsan "subsan (3 commits)")[![Basster](https://avatars.githubusercontent.com/u/1265783?v=4)](https://github.com/Basster "Basster (1 commits)")

---

Tags

codeceptionelasticsearch

### Embed Badge

![Health badge](/badges/subsan-codeception-module-elasticsearch/health.svg)

```
[![Health](https://phpackages.com/badges/subsan-codeception-module-elasticsearch/health.svg)](https://phpackages.com/packages/subsan-codeception-module-elasticsearch)
```

###  Alternatives

[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

936603.4k2](/packages/mailerlite-laravel-elasticsearch)[matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

7491.7M3](/packages/matchish-laravel-scout-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

399672.8k](/packages/jeroen-g-explorer)[jsq/amazon-es-php

Support for using IAM authentication with the official Elasticsearch PHP client

9311.4M13](/packages/jsq-amazon-es-php)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.4M6](/packages/babenkoivan-elastic-client)[heyday/silverstripe-elastica

Provides Elastic Search integration for SilverStripe DataObjects using Elastica

1138.5k2](/packages/heyday-silverstripe-elastica)

PHPackages © 2026

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