pmishev/elasticsearch-dsl-php

Elasticsearch DSL library


README

Elasticsearch DSL library to provide objective query builder for the elasticsearch-php client. You can easily build any Elasticsearch query and transform it to an array.

This is a fork of the abandoned https://github.com/ongr-io/ElasticsearchDSL

Tests Coverage Status Latest Stable Version PHP Version Require

Version matrix

Elasticsearch version Bundle version
>= 8.0 >= 8.0
>= 7.0 >= 7.0
>= 6.0, < 7.0 >= 6.0
>= 5.0, < 6.0 >= 5.0

Documentation

The online documentation of the bundle is here

Try it!

Installation

$ composer require pmishev/elasticsearch-dsl-php ^8.0

Example usage

 <?php
    require 'vendor/autoload.php'; // Composer autoload

    use Elasticsearch\ClientBuilder;
    use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
    use ONGR\ElasticsearchDSL\Search;

    // Build an elasticsearch-php client
    $clientBuilder = ClientBuilder::create();
    $clientBuilder->setHosts(['localhost:9200']);
    $client = $clientBuilder->build();
    
    $search = (new Search())->addQuery(new MatchAllQuery());
    
    $params = [
        'index' => 'your_index',
        'body'  => $search->toArray(),
    ];
    
    $results = $client->search($params);