PHPackages                             kiwfy/simple-elasticsearch-php - 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. [API Development](/categories/api)
4. /
5. kiwfy/simple-elasticsearch-php

Abandoned → [not-empty/simple-elasticsearch-php-lib](/?search=not-empty%2Fsimple-elasticsearch-php-lib)Library[API Development](/categories/api)

kiwfy/simple-elasticsearch-php
==============================

PHP library to connect to and use Elasticsearch

7.0.0(2y ago)510.3k1GPL-3.0-onlyPHPPHP ^8.3

Since Oct 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/not-empty/simple-elasticsearch-php-lib)[ Packagist](https://packagist.org/packages/kiwfy/simple-elasticsearch-php)[ RSS](/packages/kiwfy-simple-elasticsearch-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (5)Versions (9)Used By (0)

Simple Elasticsearch PHP
========================

[](#simple-elasticsearch-php)

[![Latest Version](https://camo.githubusercontent.com/a8e016f036f5b8a0efe7d060b5a7f4b0843f7cac2be89d884ea60da539a33bd9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6e6f742d656d7074792f73696d706c652d656c61737469637365617263682d7068702d6c69622e7376673f7374796c653d666c61742d737175617265)](https://github.com/not-empty/simple-elasticsearch-php-lib/releases)[![codecov](https://camo.githubusercontent.com/849751333f21611f52fb329b7d99b6881ff81b24650be1b67cfac4fd343b6cfd/68747470733a2f2f636f6465636f762e696f2f67682f6e6f742d656d7074792f73696d706c652d656c61737469637365617263682d7068702d6c69622f67726170682f62616467652e7376673f746f6b656e3d41454d56313633555736)](https://codecov.io/gh/not-empty/simple-elasticsearch-php-lib)[![CI Build](https://camo.githubusercontent.com/0d4ded94f06810cc12754ab06fad68c4d6486411885cb77946d622ca225274f8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e6f742d656d7074792f73696d706c652d656c61737469637365617263682d7068702d6c69622f7068702e796d6c)](https://github.com/not-empty/simple-elasticsearch-php-lib/actions/workflows/php.yml)[![Downloads Old](https://camo.githubusercontent.com/03d363381368ca40738f027489f06075ed0c249666b006af775d22cf95dc6f80/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b697766792f73696d706c652d656c61737469637365617263682d7068703f6c6f676f3d6f6c64266c6162656c3d646f776e6c6f6164732532306c6567616379)](https://packagist.org/packages/kiwfy/simple-elasticsearch-php)[![Downloads](https://camo.githubusercontent.com/875066fc30912877a50fced11ab9d1862f5d04484509448fd841e54a03188b75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f742d656d7074792f73696d706c652d656c61737469637365617263682d7068702d6c69623f6c6f676f3d6f6c64266c6162656c3d646f776e6c6f616473)](https://packagist.org/packages/not-empty/simple-elasticsearch-php-lib)[![PRs Welcome](https://camo.githubusercontent.com/25b3e6d0d42c98de74a98cbb4d149a1c09020cf6d1361993b72d7d5b8ffed363/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://makeapullrequest.com)[![Packagist License (custom server)](https://camo.githubusercontent.com/7f595160489aa51452e54d3c985961e5fdf4bdbcfcc9fcdba30cf0fbe088fc7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e6f742d656d7074792f73696d706c652d656c61737469637365617263682d7068702d6c6962)](https://github.com/not-empty/simple-elasticsearch-php-lib/blob/master/LICENSE)

PHP library to connect to and use Elasticsearch in a simple way.

### Installation

[](#installation)

[Release 7.0.0](https://github.com/not-empty/simple-elasticsearch-php-lib/releases/tag/7.0.0) Requires [PHP](https://php.net) 8.3

[Release 6.0.0](https://github.com/not-empty/simple-elasticsearch-php-lib/releases/tag/6.0.0) Requires [PHP](https://php.net) 8.2

[Release 5.0.0](https://github.com/not-empty/simple-elasticsearch-php-lib/releases/tag/5.0.0) Requires [PHP](https://php.net) 8.1

[Release 4.0.0](https://github.com/not-empty/simple-elasticsearch-php-lib/releases/tag/4.0.0) Requires [PHP](https://php.net) 7.4

[Release 3.0.0](https://github.com/not-empty/simple-elasticsearch-php-lib/releases/tag/3.0.0) Requires [PHP](https://php.net) 7.3

[Release 2.0.0](https://github.com/not-empty/simple-elasticsearch-php-lib/releases/tag/2.0.0) Requires [PHP](https://php.net) 7.2

[Release 1.0.0](https://github.com/not-empty/simple-elasticsearch-php-lib/releases/tag/1.0.0) Requires [PHP](https://php.net) 7.1

The recommended way to install is through [Composer](https://getcomposer.org/).

```
composer require not-empty/simple-elasticsearch-php-lib
```

### Usage

[](#usage)

Setting up connection

```
use SimpleElasticsearch\SimpleElasticsearch;
$host = 'http://localhost:9200/';
$elastic = new SimpleElasticsearch($host);
$elastic->setConnectionOptions([
    'connect_timeout' => 5,
    'timeout' => 5,
]);
```

Checking if connection is available

```
...
$isConnected = $elastic->isConnected();
var_dump($isConnected);
```

Putting an index

```
...
$indexName = 'test';
$index = $elastic->putIndex(
    $indexName
);
var_dump($index);
```

Putting a mapping

```
...
$indexName = 'test';
$mapping = [
    'properties' => [
        'name' => [
            'type' => 'keyword',
        ],
        'email' => [
            'type' => 'keyword',
        ],
        'gender' => [
            'type' => 'byte',
        ]
    ]
];
$newMapping = $elastic->putMapping(
    $indexName,
    $mapping
);
var_dump($newMapping);
```

Putting a template

```
...
$documentName = 'document';
$template = [
    'index_patterns' => [
        'document*'
    ],
    'mappings' => [
        '_source' => [
            'enabled' => true,
        ],
        'properties' => [
            'name' => [
                'type' => 'keyword',
            ],
            'created' => [
                'type'=> 'date',
                'format' => 'yyyy-MM-dd HH:mm:ss',
            ],
        ]
    ]
];
$newTemplate = $elastic->putTemplate(
    $documentName,
    $template
);
var_dump($newTemplate);
```

Getting an index

```
...
$indexName = 'test';
$getIndex = $elastic->getIndex(
    $indexName
);
var_dump($getIndex);
```

Getting a mapping

```
...
$indexName = 'test';
$getMapping = $elastic->getMapping(
    $indexName
);
var_dump($getMapping);
```

Getting a template

```
...
$documentName = 'document';
$getTemplate = $elastic->getTemplate(
    $documentName
);
var_dump($getTemplate);
```

Posting a document with template

```
...
$documentName = 'document';
$dataTemplate = [
    'name' => 'document1',
    'created' => date('Y-m-d H:i:s'),
];
$postDocumentTemplate = $elastic->postDocument(
    $documentName,
    $dataTemplate
);
var_dump($postDocumentTemplate);
```

Posting a document passing the id

```
...
$documentName = 'document';
$indexName = 'test';
$data = [
    'name' => 'user',
    'email' => 'test@test.com',
    'gender' => 0,
];
$id = '01HDRQRB0VPDDB9HWHX3MGY6XG';
$postDocument = $elastic->postDocument(
    $indexName,
    $data,
    $id
);
var_dump($postDocument);
```

Getting a document by his id

```
...
$indexName = 'test';
$id = '01HDRQRB0VPDDB9HWHX3MGY6XG';
$getDocument = $elastic->getDocument(
    $indexName,
    $id
);
var_dump($getDocument);
```

Deleting a document by his id

```
...
$indexName = 'test';
$id = '01HDRQRB0VPDDB9HWHX3MGY6XG';
$deleteDocument = $elastic->deleteDocument(
    $indexName,
    $id
);
var_dump($deleteDocument);
```

Searching documents

```
...
$indexName = 'test';
$dslQuery =  [
    'term' => [
        'email' => [
            'value' => 'test@test.com',
            'boost' => 1,
        ],
    ],
];
$searchDocuments = $elastic->searchDocuments(
    $indexName,
    $dslQuery
);
var_dump($searchDocuments);
```

Listing documents

```
...
$indexName = 'test';
$listDocuments = $elastic->listDocuments(
    $indexName
);
var_dump($listDocuments);
```

Listing documents paginated

```
...
$indexName = 'test';
$page = 2;
$listDocumentsPaginated = $elastic->listDocuments(
    $indexName,
    $page
);
var_dump($listDocumentsPaginated);
```

Executing 'SQL' querys

```
...
$query = "SELECT * FROM test WHERE email LIKE '%test@test.com' ORDER BY email DESC";
$sqlResponse = $elastic->sql(
    $query
);
var_dump($sqlResponse);
```

Executing 'SQL' querys with cursor to paginate

```
...
// var $sql has data returned from previous query with the cursor
$sqlCursorResponse = $elastic->sqlCursor(
    $sql['cursor']
);
var_dump($sqlCursorResponse);
```

Translating 'SQL' query to 'DSL' query

```
...
$query = "SELECT * FROM test WHERE email LIKE '%test@test.com' ORDER BY email DESC";
$translate = $elastic->translate(
    $query
);
var_dump($translate);
```

Deleting template

```
...
$documentName = 'document';
$deleteTemplate = $elastic->deleteTemplate(
    $documentName
);
var_dump($deleteTemplate);
```

Deleting index

```
...
$indexName = 'test';
$deleteIndex = $elastic->deleteIndex(
    $indexName
);
var_dump($deleteIndex);
```

Aggregating documents

```
...
$indexName = 'test';
$dslAgregate = [
    'genders' => [
        'terms' => [
            'field' => 'gender',
        ]
    ]
];
$dslQueryAggregate =  [
    'wildcard' => [
        'email' => [
            'wildcard' => '*1-test@test.com',
            'boost' => 1,
        ],
    ],
];
$aggregateDocuments = $elastic->aggregateDocuments(
    $indexName,
    $dslAgregate,
    $dslQueryAggregate
);
var_dump($aggregateDocuments);
```

if you want an environment to run or test it, you can build and install dependences like this

```
docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/simple-elasticsearch-php-lib:php83 -f contrib/Dockerfile .
```

Access the container

```
docker run -v ${PWD}/:/var/www/html -it not-empty/simple-elasticsearch-php-lib:php83 bash
```

Verify if all dependencies is installed

```
composer install --no-dev --prefer-dist
```

and run

```
php sample/elastic-sample.php
```

### Development

[](#development)

Want to contribute? Great!

The project using a simple code. Make a change in your file and be careful with your updates! **Any new code will only be accepted with all validations.**

To ensure that the entire project is fine:

First you need to building a correct environment to install all dependences

```
docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/simple-elasticsearch-php-lib:php83 -f contrib/Dockerfile .
```

Access the container

```
docker run -v ${PWD}/:/var/www/html -it not-empty/simple-elasticsearch-php-lib:php83 bash
```

Install all dependences

```
composer install --dev --prefer-dist
```

Run all validations

```
composer check
```

**Not Empty Foundation - Free codes, full minds**

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~5 days

Total

7

Last Release

897d ago

Major Versions

1.0.0 → 3.0.02023-10-27

3.0.0 → 4.0.02023-10-27

4.0.0 → 5.0.02023-10-27

2.0.0 → 6.0.02023-10-27

6.0.0 → 7.0.02023-11-27

PHP version history (7 changes)1.0.0PHP ^7.1

3.0.0PHP ^7.3

4.0.0PHP ^7.4

5.0.0PHP ^8.1

2.0.0PHP ^7.2

6.0.0PHP ^8.2

7.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a8e537dba9018eff457d477dba8f79158989b41ca86bd74d1c4a1186c158caa?d=identicon)[kiwfy](/maintainers/kiwfy)

---

Top Contributors

[![leodisarli](https://avatars.githubusercontent.com/u/1638455?v=4)](https://github.com/leodisarli "leodisarli (10 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/kiwfy-simple-elasticsearch-php/health.svg)

```
[![Health](https://phpackages.com/badges/kiwfy-simple-elasticsearch-php/health.svg)](https://phpackages.com/packages/kiwfy-simple-elasticsearch-php)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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