shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

Maintainers

Package info

github.com/shyim/opensearch-php-dsl

Homepage

pkg:composer/shyim/opensearch-php-dsl

Transparency log

Statistics

Installs: 7 501 439

Dependents: 10

Suggesters: 1

Stars: 18

Open Issues: 4

1.1.6 2026-07-21 09:03 UTC

README

Introducing OpenSearch DSL library to provide objective query builder for opensearch-php client. You can easily build any Opensearch query and transform it to an array.

This is a fork of ongr-io/ElasticsearchDSL, which will be more regularly updated. Thanks for ongr-io for building this Library!

If you need any help, Github issues is the preferred and recommended way to ask support questions.

Test codecov Latest Stable Version Total Downloads

Version matrix

OpenSearch version OpenSearchDSL version
>= 1.0 >= 1.0
>= 2.0 >= 1.0

Documentation

  • User Guide - Comprehensive guide with examples for building queries, aggregations, sorting, and more
  • API Documentation - Detailed reference documentation

Quick Start

Installation

Install library with composer:

composer require shyim/opensearch-php-dsl

Note: This library does not require elasticsearch/elasticsearch or opensearch-project/opensearch-php. It is a standalone query builder that generates arrays compatible with any OpenSearch client.

Basic Example

<?php

require 'vendor/autoload.php';

use OpenSearchDSL\Search;
use OpenSearchDSL\Query\MatchAllQuery;

$search = new Search();
$search->addQuery(new MatchAllQuery());

$params = [
    'index' => 'your_index',
    'body'  => $search->toArray(),
];

// Use with opensearch-php client
$client = \OpenSearch\ClientBuilder::create()->build();
$results = $client->search($params);

Features

  • Query Building: Support for all OpenSearch query types (match, term, range, bool, geo, etc.)
  • Aggregations: Bucket, metric, and pipeline aggregations
  • Sorting: Field sorting with multiple criteria
  • Highlighting: Search result highlighting
  • Suggestions: Term, phrase, and completion suggesters
  • Framework Agnostic: Works with any HTTP client or OpenSearch client library

For detailed examples and usage instructions, see the User Guide.